0

I am building a small web app that allows users to write a feedback in a MySQL database. Here is the function that takes care of writing the feedback:

public function add(Feedback $feedback) {
        $query = $this->db->prepare('INSERT INTO feedback SET country = :country, country-other = :countryOther, find-out = :findOut, find-out-other = :findOutOther, what-tour = :whatTour, booking-rating = :bookingRating, booking-comments = :bookingComments, checkin-rating = :checkinRating, checkin-comments = :checkinComments, journey-rating = :journeyRating, journey-comments = :journeyComments, guides-informative-rating = :guidesInformativeRating, guides-informative-comments = :guidesInformativeComments, guides-professional-rating = :guidesProfessionalRating, guides-professional-comments = :guidesProfessionalComments, tour-rating = :tourRating, tour-comments = :tourComments, tour-length = :tourLength, recommendation = :recommendation, comments = :comments');
        $query->bindValue(':country', $feedback->country());
        $query->bindValue(':countryOther', $feedback->countryOther());
        $query->bindValue(':findOut', $feedback->findOut());
        $query->bindValue(':findOutOther', $feedback->findOutOther());
        $query->bindValue(':whatTour', $feedback->whatTour());
        $query->bindValue(':bookingRating', $feedback->bookingRating());
        $query->bindValue(':bookingComments', $feedback->bookingComments());
        $query->bindValue(':checkinRating', $feedback->checkinRating());
        $query->bindValue(':checkinComments', $feedback->checkinComments());
        $query->bindValue(':journeyRating', $feedback->journeyRating());
        $query->bindValue(':journeyComments', $feedback->journeyComments());
        $query->bindValue(':guidesInformativeRating', $feedback->guidesInformativeRating());
        $query->bindValue(':guidesInformativeComments', $feedback->guidesInformativeComments());
        $query->bindValue(':guidesProfessionalRating', $feedback->guidesProfessionalRating());
        $query->bindValue(':guidesProfessionalComments', $feedback->guidesProfessionalComments());
        $query->bindValue(':tourRating', $feedback->tourRating());
        $query->bindValue(':tourComments', $feedback->tourComments());
        $query->bindValue(':tourLength', $feedback->tourLength());
        $query->bindValue(':recommendation', $feedback->recommendation());
        $query->bindValue(':comments', $feedback->comments());

        // $query = $this->db->prepare('INSERT INTO feedback (country) VALUES (:country)');
        // $country = $feedback->country();
        // echo $country;
        // $query->bindParam(':country', $country);
        $query->execute();
    }

Commented lines show a test I did to see if it was writing on DB, and it's not.

So the problem is that I don't get any error message. I am sure I am correctly connected to the database (this same function was working on the first draw of the project, which included a much simpler DB).

I checked the $feedback object contains all the correct parameters, and it does.

So what is my mistake, here? Thanks for your help.

eichan
  • 95
  • 13
  • Your ``INSERT INTO`` statement is wrong. ``SET`` is used in ``UPDATE`` statements. Take a look at http://www.w3schools.com/sql/sql_insert.asp – SameOldNick May 15 '16 at 03:43
  • As for why there's no error message, [``PDO::ERRMODE_SILENT``](http://php.net/manual/en/pdo.error-handling.php) is set by default – SameOldNick May 15 '16 at 03:49

1 Answers1

0

OK I must be quite stupid. I solved the problem by changing all '-' in '_' in the DB structure. Usually the simplest solutions work.

eichan
  • 95
  • 13