Cannot insert foreign key value into binding table

I am currently trying to insert data into a table named "customer_quote" , this table acts as a link table between the table "customer" and the table "customer_tariffs" . It also records the user who transferred the data using the user table .

Here is the diagram of my db:

http://i.imgur.com/LOG1T.png enter image description here

and here is a screenshot of a table that does not allow me to insert into it.

http://i.imgur.com/i2wiU.png

enter image description here

This is how I embed in my db:

  • Paste the data into the customer table
  • Get row id using mysql_insert_id
  • Paste the data into customer_quote <--- Not working!

Here is the code:

    //code above this inserted data into customer table

//get id of row where data was just inserted
$sustomer->cid = mysql_insert_id($db);

//insert into customer_quote table
$database->query("INSERT INTO customer_quote (cid)
        Values ('$customer->cid')");

** New error message **

'Unable to add or update child row: foreign key failed ( quote_system. customer_quote, CONSTRAINT fk_customer_quote_customerFOREIGN KEY ( cid) LINKS customer( id) ON DELETE NO ACTION ON UPDATE NO ACTION)'

As you can see, error feedback is useless, so after three hours of testing, I came to the conclusion that the problem is in my "cid" column in the "Client Quote" table.

It takes only certain values, however, my own php variable has the correct value, which is available for insertion through phpmyadmin, as you can see in the screenshot below.

http://i.imgur.com/eEFou.png

enter image description here

, - , ?

, .

!

+5
4

, , :

$database->query("INSERT INTO customer_quote (cid)
        Values ('$customer->cid'");

$database->query("INSERT INTO customer_quote (cid)
        Values ('$customer->cid')"); // added closing bracket on values
+2

parens

:

$database->query("INSERT INTO customer_quote (cid)
    Values ('$customer->cid'");

$database->query("INSERT INTO customer_quote (cid)
    Values ('$customer->cid')");
+2

You are missing) at the end of your insert ...

//insert into customer_quote table
$database->query("INSERT INTO customer_quote (cid) Values ('$customer->cid'");

it should be

//insert into customer_quote table
$database->query("INSERT INTO customer_quote (cid) Values ('$customer->cid')");

By the way, a good record with images, etc.

+2
source

You are missing parenthese:

"INSERT INTO customer_quote (cid) Values ('$customer->cid')"
+1
source

All Articles