spfoonnewb Posted January 11, 2007 Share Posted January 11, 2007 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 More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 is your table called tablename? Link to comment Share on other sites More sharing options...
spfoonnewb Posted January 11, 2007 Author Share Posted January 11, 2007 Ya. Ill try changing the name of it.. Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 And you're entering the string Value of lastname? Link to comment Share on other sites More sharing options...
spfoonnewb Posted January 11, 2007 Author Share Posted January 11, 2007 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 More sharing options...
Recommended Posts