Error in sql syntax, Driving me crazy!
Posted: Sun Oct 31, 2010 2:16 pm
Hi,
im new to php and im trying to just add some data to my mysql database. Ive done this with success quite a few times but i cant get this script to work, even though it is practically identical to the code ive been using sucessfullt in the same database! I keep getting the error '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 ''name', 'key') VALUES ('br','123')' at line 1 '
This is the code for my html form:
<html>
<body>
<Form name="form1" form action= "insertproductkey.php" method="post">
Software Name:
<br/>
<input type="text" Name ="Name" id="Name"><br>
Product Key:
<br/>
<input type="text" name="Key" id="key"><br>
<h1><input type="Submit" Name="submit" value="submit"></h1>
</form>
<br>
</body>
</html>
and this is the code for the php script:
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql="INSERT INTO productkey (name, key)
VALUES
('$_POST[name]','$_POST[key]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your data has been added to the Data Base, Thank you for your time.";
mysql_close($con)
?>
like i say, very simple stuff and i cant understand why it wont work! its basically just going to store some product keys in the database.
Any help would be greatly apprciated.
Regards
Harry.
im new to php and im trying to just add some data to my mysql database. Ive done this with success quite a few times but i cant get this script to work, even though it is practically identical to the code ive been using sucessfullt in the same database! I keep getting the error '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 ''name', 'key') VALUES ('br','123')' at line 1 '
This is the code for my html form:
<html>
<body>
<Form name="form1" form action= "insertproductkey.php" method="post">
Software Name:
<br/>
<input type="text" Name ="Name" id="Name"><br>
Product Key:
<br/>
<input type="text" name="Key" id="key"><br>
<h1><input type="Submit" Name="submit" value="submit"></h1>
</form>
<br>
</body>
</html>
and this is the code for the php script:
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql="INSERT INTO productkey (name, key)
VALUES
('$_POST[name]','$_POST[key]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your data has been added to the Data Base, Thank you for your time.";
mysql_close($con)
?>
like i say, very simple stuff and i cant understand why it wont work! its basically just going to store some product keys in the database.
Any help would be greatly apprciated.
Regards
Harry.