Jump to content

You have an error in your SQL syntax...


ifusion

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/97452-you-have-an-error-in-your-sql-syntax/
Share on other sites

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


?>

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

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.