nevsi79 Posted April 3, 2008 Share Posted April 3, 2008 Hey guys, I've got this script: $fieldset = $_POST['tfa_Item']; $field = $_POST['tfa_ItemName']; print_r($field); echo"<br/>"; $field1 = $_POST['tfa_ItemMake']; print_r($field1); echo"<br/>"; $field2 =$_POST['tfa_ItemDetails']; print_r($field2); echo"<br/>"; $field3 =$_POST['tfa_ItemPrice']; print_r($field3); echo"<br/>"; $q1 = "INSERT INTO items_claimed (master_id) VALUES ('$master_id')"; for ($i = 0; $i < count($field); $i++) $qSet[] = '(\'' . $field[$i] . '\', \'' . $field2[$i] . '\', \'' . $field2[$i] . '\', \'' . $field3[$i] . '\')'; $q = 'INSERT INTO items_claimed (`item_name`, `item_make`, `item_details`, `item_price`) VALUES ' . implode(', ', $qSet); if (!mysql_query($q) ) echo 'could not add!<br>' . mysql_error(); which is doing a great job - inserting an array in mySql db table: However I now want to connect tables and I am using: $master_id = mysql_insert_id($connect); So far so good but when I change the query to: $q = 'INSERT INTO items_claimed (`master_id`, `item_name`, `item_make`, `item_details`, `item_price`) VALUES ' . $master_id .' , ' . implode(', ', $qSet); displays the following 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 '84 , ('desk', 'oak', 'oak', '789'), ('notebook', 'nice', 'nice', '')' at line 1 where 84 is the master id, ('desk', 'oak', 'oak', '789') - is my first array and ('notebook', 'nice', 'nice', '') - my second array within the multidimensional array. Any help will be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/99376-need-help-with-mysql-syntax-please/ Share on other sites More sharing options...
EXiT Posted April 3, 2008 Share Posted April 3, 2008 Hi, Replace this line $q = 'INSERT INTO items_claimed (`master_id`, `item_name`, `item_make`, `item_details`, `item_price`) VALUES ' . $master_id .' , ' . implode(', ', $qSet); with this $q = 'INSERT INTO items_claimed (`master_id`, `item_name`, `item_make`, `item_details`, `item_price`) VALUES (' . $master_id .' , ' . implode(', ', $qSet)); I think you have missed out the () after VALUES. Still learning myself, so im not 100% sure if this is the actual problem. Quote Link to comment https://forums.phpfreaks.com/topic/99376-need-help-with-mysql-syntax-please/#findComment-508464 Share on other sites More sharing options...
nevsi79 Posted April 3, 2008 Author Share Posted April 3, 2008 thank you, but no, it came up with a php syntax error for this line when i replaced it :-\ Quote Link to comment https://forums.phpfreaks.com/topic/99376-need-help-with-mysql-syntax-please/#findComment-508471 Share on other sites More sharing options...
paul2463 Posted April 3, 2008 Share Posted April 3, 2008 it is missing a closing speech mark Quote Link to comment https://forums.phpfreaks.com/topic/99376-need-help-with-mysql-syntax-please/#findComment-508475 Share on other sites More sharing options...
MadTechie Posted April 3, 2008 Share Posted April 3, 2008 try this $q = 'INSERT INTO items_claimed (`master_id`, `item_name`, `item_make`, `item_details`, `item_price`) VALUES (' . $master_id .' , \'' . implode('\', \'', $qSet).'\')'; i only skimmed the question (note they are 2x single quotes,not double quotes) Quote Link to comment https://forums.phpfreaks.com/topic/99376-need-help-with-mysql-syntax-please/#findComment-508476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.