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:
and here is a screenshot of the table that is not allowing me to insert into it.
This is the process in how I insert into my db:
- Insert data into customer table
- Retrieve row id using mysql_insert_id
- Insert 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**
'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.
So it has to be the constraints or something else in my table that is stopping me?
Any ideas how to solve this.
Thanks!
You are missing a parenthese:
I really hope its a simple typo in your question but your query isn't correct :
should be
You have misplaced the double quote and missed a parens
Change the lines:
to
You have a missing ) at the end of your insert...
should be
BTW, nice post with images, etc...