So basically I have been trying to insert columns into my third table from columns extracted from 2 tables in prior.
I have one info table which stores information of users,
one image table which stores head photos of users,
and one id table which is like a reference table,designed to display correct head photos associated to correct users when necessary(like user querying or simply displaying…)
My code:
$result_1 = mysql_query("SELECT info_id FROM info WHERE info_name = '$_POST[name]'");
$result_2 = mysql_query("SELECT image_id FROM image WHERE image_name = '$_FILES[file][name]'");
$sql = "INSERT INTO id_table (main_id, id_info, id_image)
VALUES (NULL, $result_1, $result_2);";
if(!mysql_query($sql,$connect_database)){
die('Error: ',mysql_error());
}
So the codes above simply illustrated my idea:
1. get the id of info from info table
2. get the id of image from image table
3. insert both ids into columns in id_table respectively
Then I got this error information:
Error: 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 ‘id #4, Resource id #5 )’ at line 1
I could not figure out where the problem is…
$result_1and$result_2just contain pointers to the results. you still have to loop through them to get the actual values.Try this: