a_bains Posted February 26, 2008 Share Posted February 26, 2008 I keep getting this error: Could not add customer: 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 ''computers'('case', 'psu', 'cpu', 'mobo', 'ram', 'hdd', 'video', 'drives', 'pci'' at line 1 I have tried many different variations, like '$_POST[mobo]', ..... no success in any way The code is below, <?php $title="Add PC"; include("header.php"); echo "<div id='nav'><a href='details.php'>Details</a> | <a href='workorder.php'>Add Work Order</a> | <a href='addpc.php'>Add PC</a> | <a href='index.php'>Search</a></div>"; if ($submit == "yes") { require("connect.php"); $sql = "INSERT INTO 'computers'('case', 'psu', 'cpu', 'mobo', 'ram', 'hdd', 'video', 'drives', 'pci', 'other') VALUES('" . $_POST['serial-case'] . "', '" . $_POST['serial-psu'] . "', '" . $_POST['serial-cpu'] . "', '" . $_POST['serial-mobo'] . "', '" . $_POST['serial-ram'] . "', '" . $_POST['serial-hdd'] . "', '" . $_POST['serial-video'] . "', '" . $_POST['serial-drives'] . "', '" . $_POST['serial-pci'] . "', '" . $_POST['serial-other'] . "')"; mysql_query($sql) or die('Could not add customer: ' . mysql_error()); mysql_close($con); } ?> <form name="create" method="post" action="<?=$PHP_SELF?>"> <table class="form"> <tr style="text-align:center"> <td></td> <td>Serial</td> <td>Description</td> </tr> <tr> <td><label for="case">Case</label></td> <td><input name="serial-case"></td> <td><input name="info-case"></td> </tr> <tr> <td><label for="psu">Power Supply</label></td> <td><input name="serial-psu"></td> <td><input name="info-psu"></td> </tr> <tr> <td><label for="cpu">Processor</label></td> <td><input name="serial-cpu"></td> <td><input name="info-cpu"></td> </tr> <tr> <td><label for="mobo">Motherboard</label></td> <td><input name="serial-mobo"></td> <td><input name="info-mobo"></td> </tr> <tr> <td><label for="hdd">Hard Drive</label></td> <td><input name="serial-hdd"></td> <td><input name="info-hdd"></td> </tr> <tr> <td><label for="video">Video Card</label></td> <td><input name="serial-video"></td> <td><input name="info-video"></td> </tr> <tr> <td><label for="ram">Memory</label></td> <td><input name="serial-ram"></td> <td><input name="info-ram"></td> </tr> <tr> <td><label for="drives">Drives</label></td> <td><input name="serial-drives"></td> <td><input name="info-drives"></td> </tr> <tr> <td><label for="pci">PCI</label></td> <td><input name="serial-pci"></td> <td><input name="info-pci"></td> </tr> <tr> <td><label for="other">Other</label></td> <td><input name="serial-other"></td> <td><input name="info-other"></td> </tr> <tr> <input type="hidden" name="submit" value="yes" /> <td colspan="2" align="center"><br><input type="submit" value="Add PC"></td> </tr> </table> </form> <?php include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/ Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 Try This.... ?php $title="Add PC"; include("header.php"); echo "<div id='nav'><a href='details.php'>Details</a> | <a href='workorder.php'>Add Work Order</a> | <a href='addpc.php'>Add PC</a> | <a href='index.php'>Search</a></div>"; if ($submit == "yes") { require("connect.php"); $sql = "INSERT INTO 'computers'('case', 'psu', 'cpu', 'mobo', 'ram', 'hdd', 'video', 'drives', 'pci', 'other') VALUES('$_POST[serial-case]','$_POST[serial-psu]','$_POST[serial-cpu]','$_POST[serial-mobo]','$_POST[serial-ram]' ,'$_POST[serial-hdd]','$_POST[serial-video]','$_POST[serial-drives]','$_POST[serial-pci]','$_POST[serial-other]')"; mysql_query($sql) or die('Could not add customer: ' . mysql_error()); mysql_close($con); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476785 Share on other sites More sharing options...
a_bains Posted February 26, 2008 Author Share Posted February 26, 2008 still same error, Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\wdt\cci\addpc.php on line 13 thx tho.. Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476786 Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 Try it again i updated it. Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476788 Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 line #13 $sql = "INSERT INTO computers (case, psu, cpu, mobo, ram, hdd, video, drives, pci, other) VALUES('$_POST[serial-case]','$_POST[serial-psu]','$_POST[serial-cpu]','$_POST[serial-mobo]','$_POST[serial-ram]' ,'$_POST[serial-hdd]','$_POST[serial-video]','$_POST[serial-drives]','$_POST[serial-pci]','$_POST[serial-other]')"; Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476789 Share on other sites More sharing options...
a_bains Posted February 26, 2008 Author Share Posted February 26, 2008 With each of your suggestions i am getting this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in C:\xampp\htdocs\wdt\cci\addpc.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476790 Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 give me on sec Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476791 Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 My IDE says the dashes are messing it up.... If you do it with out the dashes it says its ok <?php mysql_query ("INSERT INTO computers ('case', 'psu', 'cpu', 'mobo', 'ram', 'hdd', 'video', 'drives', 'pci', 'other') VALUES('$_POST[serialcase]','$_POST[serialpsu]','$_POST[serialcpu]','$_POST[serialmobo]','$_POST[serialram]' ,'$_POST[serialhdd]','$_POST[serialvideo]','$_POST[serialdrives]','$_POST[serialpci]','$_POST[serialother]')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476795 Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 You know what, I've never had any luck trying to inject array elements, a pain in the butt, but I have always had to turn them into strings Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476797 Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 I agree with dark... Always turns out to be a pain in the ass. Just define them into string. Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476798 Share on other sites More sharing options...
a_bains Posted February 26, 2008 Author Share Posted February 26, 2008 not too sure what you mean, is this what you mean? $serialcase = $_POST['serialcase'] "INSERT INTO computers (case, psu, cpu, mobo, ram, hdd, video, drives, pci, other) VALUES('$serialcase','$serialmobo',................ thx for all the help Quote Link to comment https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/#findComment-476803 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.