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


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.