php - SQL Syntax validation


Here is my database structure:

enter image description here

Here is the snippet of my TimeSlot.php:

    public $hasMany = array(
    'Response' => array(
        'className' => 'Response',
        'foreignKey' => 'time_slot_id`'

and Response.php:

   public $belongsTo = array(
    'TimeSlot' => array(
        'className' => 'TimeSlot',
        'foreignKey' => 'time_slot_id'

When I add this line to my action in Meetings Controller:

  $time_slot = $this->TimeSlot->find("first");

This results to:

   Database Error
   Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL    syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`.`responses` AS `Response` WHERE `Response`.`time_slot_id` = (1)' at line 1

   SQL Query: SELECT `Response`.`id`, `Response`.`invitee_id`, `Response`.`time_slot_id`, `Response`.`time_slot_id`` FROM `meetingscheduler`.`responses` AS `Response` WHERE `Response`.`time_slot_id` = (1)

I'm a little confused whats wrong with my codes. But I think its the relations ship between TimeSlot and Response Models because once I ignore the ralationships, its working fine.




You have an extra tick here:


People are also looking for solutions to the problem: mysql - PHP Insert from form


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.