Jump to content

Help! Mysql Error!


spfoonnewb

Recommended Posts

I created this code, it worked fine... when I didnt have $firstname and $lastname in the query.. now it doesn't insert anything at all, and says:

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 'tablename (firstname, lastname) VALUES ('Value of firstname','Value of lastname')' at line 1

[code]<form action="" method="post">
First Name:<br /><input type="text" name="firstname"><br /><br />
Last Name:<br /><input type="text" name="lastname"><br /><br />
<input type="submit" value="Submit">
</form>

<?php

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];

if (!empty($firstname) && ($lastname)) {

mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("tablename") or die(mysql_error());

mysql_query("INSERT INTO tablename (firstname, lastname) VALUES ('" . $firstname . "','" . $lastname . "') ") or die(mysql_error());

echo "Thank you!";

}

else {

echo "";

}

?>


[/code]
Link to comment
Share on other sites

Wow.. lame, well I changed the table name.. and used this query.. and it worked. I guess the tablename can't be table cause if I change it to that its an error. Oh well. Thanks.

[code]mysql_query("INSERT INTO test
(firstname, lastname) VALUES('$firstname', '$lastname' ) ")
or die(mysql_error());  [/code]
Link to comment
Share on other sites

Guest
This topic is now 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.