tball1 Posted May 7, 2010 Share Posted May 7, 2010 Hello, Can someone please tell what is wrong with this I keep getting SQL 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" . I can't seem to find what is wrong with it. foreach ($_POST['po_item'] as $row=>$name) { $poid = $PoId; // comes from above returned insert id. $poitem = $name; $qty = $_POST['qty'][$row]; $rate = $_POST['rate'][$row]; $linetotal = $_POST['line_item_total'][$row]; mysql_query('INSERT INTO po_line_items (poid,po_item,qty,rate,line_item_total) VALUES("'.$poid.','.$poitem.','.$qty.','.$rate.','.$linetotal.')') or die(mysql_error()); //mysql_query('INSERT INTO `mytable` VALUES("' . $username . '", ' . $phonenum . ')') or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/201038-for-each-mysql_insert/ Share on other sites More sharing options...
.Stealth Posted May 7, 2010 Share Posted May 7, 2010 Try this: foreach ($_POST['po_item'] as $row=>$name) { $poid = $PoId; // comes from above returned insert id. $poitem = $name; $qty = $_POST['qty'][$row]; $rate = $_POST['rate'][$row]; $linetotal = $_POST['line_item_total'][$row]; mysql_query("INSERT INTO po_line_items (poid,po_item,qty,rate,line_item_total) VALUES('$poid','$poitem','$qty','$rate','$linetotal')") or die(mysql_error()); //mysql_query('INSERT INTO `mytable` VALUES("' . $username . '", ' . $phonenum . ')') or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/201038-for-each-mysql_insert/#findComment-1054748 Share on other sites More sharing options...
tball1 Posted May 7, 2010 Author Share Posted May 7, 2010 Thank you that did the trick! Link to comment https://forums.phpfreaks.com/topic/201038-for-each-mysql_insert/#findComment-1054763 Share on other sites More sharing options...
.Stealth Posted May 7, 2010 Share Posted May 7, 2010 It is your quotes, compare these 2 lines: mysql_query("INSERT INTO po_line_items (poid,po_item,qty,rate,line_item_total) VALUES('$poid','$poitem','$qty','$rate','$linetotal')") mysql_query('INSERT INTO po_line_items (poid,po_item,qty,rate,line_item_total) VALUES("'.$poid.','.$poitem.','.$qty.','.$rate.','.$linetotal.')') You're using single quotes in single quotes. Use single quotes in double quotes and when your trying to do what you are, for example using variables in mysql_query(), use double quotes and you don't need to link them via the dots. Link to comment https://forums.phpfreaks.com/topic/201038-for-each-mysql_insert/#findComment-1054773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.