newFreakHiba Posted May 17, 2013 Share Posted May 17, 2013 hello i am totally new to php am trying to send data to my table in sql and data isnt sent! $ind=0; // Create connection $con=mysqli_connect("localhost","root","","orders"); // Check connection if (mysqli_connect_errno($con)){echo "Failed to connect to MySQL: " . mysqli_connect_error();} while($ind<$_SESSION['index']) { $tempdate=date("Y-m-d"); $buyer=$_SESSION['views'][0]; $pid=$_SESSION['productids'][$ind]; $pname=$_SESSION['productbought'][$ind]; $price=$_SESSION['price'][$ind]; $q=$_SESSION['quantityofeachproduct'][$ind]; $sql="INSERT INTO order (pid, bid, price, pname, dateoforder, quantity) VALUES ('$pid','$buyer','$price','$pname','$tempdate','$q')"; mysqli_query($con, $sql); var_dump($sql); $ind++; Quote Link to comment https://forums.phpfreaks.com/topic/278090-information-not-sent-to-the-sql/ Share on other sites More sharing options...
jazzman1 Posted May 17, 2013 Share Posted May 17, 2013 Never ever run queries in loop, It’s so easy to start hammering the database with a crazy number of queries. So, turn on your error_reporting and also check out that thread - http://forums.phpfreaks.com/topic/267013-looping-multiple-rows-into-database/ Quote Link to comment https://forums.phpfreaks.com/topic/278090-information-not-sent-to-the-sql/#findComment-1430631 Share on other sites More sharing options...
newFreakHiba Posted May 17, 2013 Author Share Posted May 17, 2013 This is what I'm getting as an 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 'order (pid, bid, price, pname, dateoforder, quantity) VALUES ('pr000005','cl0000' at line 1 SQL: INSERT INTO order (pid, bid, price, pname, dateoforder, quantity) VALUES ('pr000005','cl000002','2499','Augi Quest ','2013-05-17','1') I tried all the combinations of syntax(by removing or adding these '') but still don't know what to do? it's not adding the type of inputs are all compatible I don't see any contradictions. Quote Link to comment https://forums.phpfreaks.com/topic/278090-information-not-sent-to-the-sql/#findComment-1430650 Share on other sites More sharing options...
Jessica Posted May 17, 2013 Share Posted May 17, 2013 order is a reserved word. Call the table something else, or use backticks. `order` Quote Link to comment https://forums.phpfreaks.com/topic/278090-information-not-sent-to-the-sql/#findComment-1430651 Share on other sites More sharing options...
newFreakHiba Posted May 17, 2013 Author Share Posted May 17, 2013 Yess. It's working now. Thank you Jessica. Quote Link to comment https://forums.phpfreaks.com/topic/278090-information-not-sent-to-the-sql/#findComment-1430655 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.