oubipaws Posted January 31, 2007 Share Posted January 31, 2007 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 https://forums.phpfreaks.com/topic/36413-solved-updating-table-error/ Share on other sites More sharing options...
toplay Posted January 31, 2007 Share Posted January 31, 2007 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 https://forums.phpfreaks.com/topic/36413-solved-updating-table-error/#findComment-173274 Share on other sites More sharing options...
oubipaws Posted January 31, 2007 Author Share Posted January 31, 2007 Thank you so much! I knew it had to be something simple that I was missing. I highly appreciate it! Link to comment https://forums.phpfreaks.com/topic/36413-solved-updating-table-error/#findComment-173813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.