ifusion Posted March 23, 2008 Share Posted March 23, 2008 Hi there! Just doing some php and keep getting this error when i submit the information: "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 'table (title, budget, description, url, email) VALUES ('Title goes here', '6', ' at line 1" It must be something simple? This is my html - testin.html <html> <body> <form name="form1" action="test.php" method="post"> Title: <input type="text" size="30" maxlength="60" name="title" /><p> Budget: <input type="text" size="30" maxlength="60" name="budget" /><p> Description:<br> <textarea cols="40" rows="5" wrap="OFF" name="description"></textarea><p> Url: <input type="text" size="30" maxlength="60" name="url" /><p> Email: <input type="text" size="30" maxlength="60" name="email" /><p> <input type="submit" value="Submit" name="submit" /> </form> </body> </html> PHP - test.php <?php mysql_connect('localhost', 'auction_ifusion', 'password') or die (mysql_error()); mysql_select_db('auction_test') or die (mysql_error()); $title = $_POST['title']; $budget = $_POST['budget']; $descrip = $_POST['description']; $url = $_POST['url']; $email = $_POST['email']; mysql_query("INSERT INTO table (title, budget, description, url, email) VALUES ('$title', '$budget', '$descrip', '$url', '$email')") or die (mysql_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 'table (title, budget, description, url, email) VALUES ('Title goes here', '6', ' at line 1 Cheers, Fusion. Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted March 23, 2008 Share Posted March 23, 2008 mysql_query("INSERT INTO `table` (`title`, `budget`, `description`, `url`, `email`) VALUES ('$title', '$budget', '$descrip', '$url', '$email')") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
Nhoj Posted March 23, 2008 Share Posted March 23, 2008 If that doesnt work; <?php mysql_connect('localhost', 'auction_ifusion', 'password') or die (mysql_error()); mysql_select_db('auction_test') or die (mysql_error()); $title = $_POST['title']; $budget = $_POST['budget']; $descrip = $_POST['description']; $url = $_POST['url']; $email = $_POST['email']; mysql_query("INSERT INTO `table` (`title`, `budget`, `description`, `url`, `email`) VALUES ('{$title}', '{$budget}', '{$descrip}', '{$url}', '{$email}')") or die (mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 23, 2008 Share Posted March 23, 2008 Change this <?php mysql_query("INSERT INTO table (title, budget, description, url, email) VALUES ('$title', '$budget', '$descrip', '$url', '$email')") or die (mysql_error()); ?> to <?php $q = "INSERT INTO `table` (title, budget, description, url, email) VALUES ('$title', '$budget', '$descrip', '$url', '$email')"; $rs = mysql_query($q) or die ("Problem with the query: $q<br>" . mysql_error()); ?> This will show you what the query is that is causing the problem, which is that the word "table" is a reserved word in MySQL and needs to be surrounded by backticks. Ken Quote Link to comment Share on other sites More sharing options...
ifusion Posted March 23, 2008 Author Share Posted March 23, 2008 Brilliant! Thanks heaps all fixed now, just had to add the little `` to the table and its contents. Thanks heaps! Quote Link to comment 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.