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
https://forums.phpfreaks.com/topic/257190-error-with-update-syntax/
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);
}

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.