0

所以我要做的是获取由表课程插入生成的 ID,然后将其分配给我的第二个表 course_locations 中的一个字段。第一个 stmt 没有问题,但是我收到第二个 stmt2 的以下错误。

“致命错误:未捕获的错误:调用 C:\xampp\htdocs\HED2\models\class.newcourse.php:94 中布尔值的成员函数 bind_param() 堆栈跟踪:#0 C:\xampp\htdocs\HED2\ admin_addcourse.php(29): Course->userAddCourse() #1 {main} 在第 94 行的 C:\xampp\htdocs\HED2\models\class.newcourse.php 中抛出"

有任何想法吗?

<?php

    class Course
    {
        public $course_active = 0;
        public $status = false;
        private $course_name;
        private $course_app_num;
        private $course_web_des;
        private $course_type;
        private $couse_sdate;
        private $course_edate;
        private $course_time;
        private $course_length;
        private $course_credit;
        private $course_cost;
        private $location_id;
        public $sql_failure = false;
        public $success = NULL;

        function __construct($cname,$cappnum,$coursewebdes,$coursetype,$csdate,$cedate,$ctime,$clength,$ccredit,$ccost,$locId)
        {
            //Used for display only
            $this->course_name = $cname;
            $this->course_app_num = $cappnum;
            $this->course_web_des = $coursewebdes;
            $this->course_type = $coursetype;
            $this->course_sdate = $csdate;
            $this->course_edate = $cedate;
            $this->course_time = $ctime;
            $this->course_length = $clength;
            $this->course_credit = $ccredit;
            $this->course_cost = $ccost;
            $this->location_id = $locId;

                //No problems have been found.
                $this->status = true;
        }

        public function userAddCourse()
        {
            global $mysqli,$websiteUrl,$db_table_prefix;

                    //Instant account activation
                    $this->course_active = 1;
                    $this->success = lang("COURSE_ADD_COMPLETE_TYPE");

                    //Insert the user into the database providing no errors have been found.
                    $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."courses (
                        course_name,
                        course_app_num,
                        course_web_des,
                        course_type,
                        course_sdate,
                        course_edate,
                        course_time,
                        course_length,
                        course_credit,
                        course_cost,
                        course_active,
                        sign_up_stamp
                        )
                        VALUES (
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        ?,
                        '".time()."'
                        )");



                    $stmt->bind_param("ssssssssssi", $this->course_name, $this->course_app_num, $this->course_web_des, $this->course_type, $this->course_sdate, $this->course_edate, $this->course_time, $this->course_length, $this->course_credit, $this->course_cost, $this->course_active);
                    $stmt->execute();
                    $inserted_id = $mysqli->insert_id;
                    $this->inserted_id = $inserted_id;    

                    $stmt2 = $mysqli->prepare("INSERT INTO ".$db_table_prefix."course_locations (
                        course_id,
                        location_id,
                        )
                        VALUES (
                        ?,
                        ?
                        )");

                    $stmt2->bind_param("ss", $this->inserted_id, $this->location_id);
                    $stmt2->execute();
                    $inserted_id = $mysqli->insert_id;

                    $stmt->close();
                    $stmt2->close();

        }

    }

    ?>
4

0 回答 0