mysqli_stmt_execute问题

时间:2015-07-23 20:49:29

标签: php sql

我正在尝试在php中调试问题。本质上,代码试图将用户的电影评论添加到数据库中。如果它已经存在,它只是更新。

当运行mysqli_stmt_execute($ query)时,由于某种原因,if语句中sql语句内的代码由于某种原因返回false。

我确定错误位于mysqli_stmt_execute中,虽然我不知道为什么。

有没有人有任何想法可能导致此错误。

 public function insertRatings($movieName, $username, $rating, $major, $comment) {
        $json = array();
        $connection = $this->db->getDb();
        $query = mysqli_prepare($connection, "INSERT INTO " . $this->db_table . " (movie, username, rating, major, comment) VALUES ('$movieName', '$username', '$rating', '$major', '$comment')");
        $firstBool = mysqli_stmt_execute($query);
        $query2 = mysqli_prepare($connection, "SELECT * FROM " . $this->db_table2 . " WHERE movie = '$movieName' AND major = '$major'");
        $query3 = mysqli_prepare($connection, "INSERT INTO recommendations (major, movie, rating, numratings) VALUES ('$major', '$movieName', '$rating', 1)");
        $secondBool = mysqli_stmt_execute($query3);
        mysqli_stmt_execute($query2);
        if (mysqli_stmt_num_rows($query2) == 0) {
          $query3 = mysqli_prepare($connection, "INSERT INTO recommendations (major, movie, rating, numratings) VALUES ('$major', '$movieName', '$rating', 1)");
          $secondBool = mysqli_stmt_execute($query3);
        }

0 个答案:

没有答案