Jump to content

unexpected T_ENCAPSED_AND_WHITESPACE


a_bains

Recommended Posts

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"); ?>

Link to comment
https://forums.phpfreaks.com/topic/93061-unexpected-t_encapsed_and_whitespace/
Share on other sites

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);

}

?>

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]')";

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]')");
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.