I want to select one row of a table and insert in another existing table.
(I use php and MySql. The two tables have the same columns except the id and the timestamp)
I try to make a cart. I want that when someone pays, select all the products of that client and that session from “carret” and insert into “comandes”.
The insert – select works if I say for instance WHERE session=4");
This works too: echo session_id(); So I can get the session
But this two things does not work together. I don’t understand the problem. What is wrong with my where condition?
mysql_query("INSERT INTO comandes (session,client,producte,preu_comanda,quantitat)
SELECT session,client,producte,preu_unitat,quantitat
FROM carret
WHERE session='".session_id()."'");
I tried too without success: WHERE client='$_SESSION[client]'
I finally find the problem with a simple “;” at the end. I post it because it could help to other php beginners like me.
This works:
This does not works!! The problem is with the final “;” if after that there is the “or die …”:
This works. Now I see that, if there is the final “or die…” I should remove the previous “;”