0

I am trying to debug an issue in php. Essentially, the code is trying to add a movie review by a user into a database. if it already exists, it simply updates.

When the mysqli_stmt_execute($query) is run, for some reason, code inside the sql statements in the if statements return false for some reason.

I determined for sure that the error lies within the mysqli_stmt_execute, although I have no idea why.

Does anyone have any ideas what could be causing this error.

 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);
        }
Akshay
  • 91
  • 9
  • 1
    false = failure, and you never bothered checking for failure. plus you're vulnaerble to [sql injection attacks](http://bobby-tables.com). Never EVER assume success on db operations. always check for failure and treat success as a pleasant surprise. `if (!$firstbool) { die(mysqli_error(...)); }` – Marc B Jul 23 '15 at 20:53
  • You're testing the number of rows returned by `query2`, but you've never actually executed it. –  Jul 23 '15 at 20:53

0 Answers0