I am currently trying to insert data into a table called "customer_quote", this table acts as a linking table between the "customer" table and the "customer_tariffs" table. It also records the user who sumbitted the data via the "user" table.
Here is a schema of my db:
http://i.imgur.com/LOG1T.png
and here is a screenshot of the table that is not allowing me to insert into it.
http://i.imgur.com/i2wiU.png
This is the process in how I insert into my db:
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**
'Cannot add or update a child row: a foreign key constraint fails (
quote_system
.customer_quote
, CONSTRAINTfk_customer_quote_customer
FOREIGN KEY (cid
) REFERENCEScustomer
(id
) ON DELETE NO ACTION ON UPDATE NO ACTION)'
As you can see that error feedback is useless , so after about three hours of testing I have concluded that the problem is my "cid" column in the "customer quote" table.
It only accepts certain values however my own php variable has the correct value which is available to insert via phpmyadmin as you can see in the screenshot below.
http://i.imgur.com/eEFou.png
So it has to be the constraints or something else in my table that is stopping me?
Any ideas how to solve this.
Thanks!
I really hope its a simple typo in your question but your query isn't correct :
$database->query("INSERT INTO customer_quote (cid)
Values ('$customer->cid'");
should be
$database->query("INSERT INTO customer_quote (cid)
Values ('$customer->cid')"); // added closing bracket on values
You have misplaced the double quote and missed a parens
Change the lines:
$database->query("INSERT INTO customer_quote (cid)
Values ('$customer->cid'");
to
$database->query("INSERT INTO customer_quote (cid)
Values ('$customer->cid')");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With