Jump to content

[SOLVED] Updating Table Error


oubipaws

Recommended Posts

First off, the error message:
[code]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 'WHERE id='7'' at line 1[/code]

Now for the who, what, when, and where;  I have a website and I am designing a small content management system, but I haven't really messed with PHP in roughly 2 years so I'm a little bit rusty.  I have many (roughly 15-20 tables) tables and I'm trying to write a simple update script.  I thought it would be uberly easy, but apparently it is not.

Here is my code for the first table's page, called templates.php:
[code]<?php
$username="removed";
$password="removed";
$database="templates";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if (isset($_GET['id'])){
$query = "SELECT * FROM templates WHERE id ='" .$_GET['id']. "'";
$result = mysql_query($query) OR die('Error: ' . mysql_error());
} else {
echo "No item selected";
}

echo "<br><br>";
while($r=mysql_fetch_array($result)){

$id = $r["id"];

$preview = $r["preview"];

$name = $r["name"];

$code = $r["code"];

}

?>
<form action="update-templates.php" method="post">
ID #:<input type="text" name="ud_id" value="<? echo $id; ?>">
Preview: <input type="text" name="ud_preview" value="<? echo $preview; ?>"><br>
Name: <input type="text" name="ud_name" value="<? echo $name; ?>"><br>
Code: <textarea name="ud_code" rows=10 cols=40><? echo $code; ?></textarea><br>
<input type="Submit" value="Update">
</form>[/code]

Then the update-templates.php php code:
[code]<?
$username="removed";
$password="removed";
$database="templates";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$ud_id=$_POST['ud_id'];
$ud_preview=$_POST['ud_preview'];
$ud_name=$_POST['ud_name'];
$ud_code=$_POST['ud_code'];


$query = "UPDATE templates SET preview='$ud_preview', name='$ud_name', code='$ud_code', WHERE id='$ud_id'";
$result = mysql_query($query) or die(mysql_error());
?>[/code]

Any thoughts?  Any suggestions?  I highly appreciate any help or advice guys!
-N
Link to comment
Share on other sites

Change this:
$query = "UPDATE templates SET preview='$ud_preview', name='$ud_name', code='$ud_code', WHERE id='$ud_id'";

to this:
$query = "UPDATE templates SET preview='$ud_preview', name='$ud_name', code='$ud_code' WHERE id = '$ud_id'";

You have an extra comma before the "WHERE".
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.