Jump to content

Error with UPDATE syntax


Icebergness

Recommended Posts

Hi,

 

I am trying to update two columns on one table from a form. The table is called pages, and there are three columns:

id (auto-increments)

name

content

 

When I try to update 'name' and 'content', I get the following error:

 

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 '1' at line 1.

 

The form simply calls the following script on submittal :

 

<?php

$name = $_POST[name];
$content = $_POST[content];

include ("../index_files/mysql_include.php");

$result = mysql_query("UPDATE pages SET name = '$name', content = '$content' WHERE id = $id");

if (!mysql_query($result, $connection))
{
die('Error: ' . mysql_error());
}

mysql_close($connection);

?>

 

Can anyone see where I'm going wrong? I've tried several different variations of the code with no joy.

 

I should point out that the above code does update MySQL successfully, but it keeps coming out with this error which I'd rather not have :)

 

Thanks,

Dave

Link to comment
Share on other sites

you are calling mysql_query() on a query resource.

 

if (!mysql_query($result, $connection))
{
die('Error: ' . mysql_error() . "<br />" . $sql);
}

 

It should read something like this:

 

$sql = "UPDATE pages SET name = '$name', content = '$content' WHERE id = $id"
$result = mysql_query($sql);

if (!$result)
{
die('Error: ' . mysql_error() . "<br />" . $sql);
}

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.