rebeat Posted May 1, 2007 Share Posted May 1, 2007 H, i have a simple database i wish to UPDATE via a form using php 5 / mysql 5. The way i call the item to edit is via: /manageedit.php?id=3 (example <a href=http://agtrac.com.au/test1/manageedit.php?id=3>here</a>) this should display the current values from the database but is not showing anything and upon submit returns: 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 'special2 = '' WHERE id =' at line 1 UPDATE products SET title = '', description = '', retail = '', special = '' special2 = '' WHERE id = I need the valued service of an expert to point out to me what the missing link is. I have spent days going around in circles trying various methods from database tutorials, with no success. If someone can assist i would be very greatful, hope i have included enough info. The current source code is below: <a href=http://agtrac.com.au/test1/manageedit.php?id=3>manageedit.php</a> <?php $usr = "user"; $pwd = "pass"; $db = "dbname"; $host = "localhost"; #connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> <HTML> <HEAD> <TITLE>Update Link</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> <TABLE WIDTH="100%"> <TR><TD><FONT SIZE=5><B> Update Link </B> </FONT></TD> <TD VALIGN=TOP ALIGN=RIGHT><FONT SIZE="-1"><A HREF="javascript: self.close()">Close Window</A></FONT></TD> </TR></TABLE> <? # processed when form is submitted back onto itself if (isset($_POST['submit'])) { # setup SQL statement $SQL = " UPDATE products SET"; $SQL = $SQL . " title = '$title', "; $SQL = $SQL . " description = '$description', "; $SQL = $SQL . " retail = '$retail', "; $SQL = $SQL . " special = '$special' "; $SQL = $SQL . " special2 = '$special2' "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); # check for errors if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P><B> Link Updated</B></P>\n"); } else { # display edit form (not post method) # setup SQL statement to retrieve link # that we want to edit $SQL = " SELECT * FROM products "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $ret = mysql_select_db($db,$SQL,$cid); # retrieve values $row = mysql_fetch_array($ret); $title = $row["title"]; $description = $row["description"]; $retail = $row["retail"]; $special = $row["special"]; $special2 = $row["special2"]; ?> <FORM NAME="fa" ACTION="manageedit.php" METHOD="POST"> <INPUT TYPE="hidden" NAME="id" VALUE="<?php echo("$id"); ?>"> <TABLE> <TR><TD><B>Title: </B> </TD><TD><INPUT TYPE="text" NAME="category" VALUE="<?php echo("$title"); ?>" SIZE=70></TD></TR> <TR><TD><B>Description:</B> </TD><TD><TEXTAREA NAME="description" ROWS=5 COLS=40><?php echo("$description"); ?></TEXTAREA></TD></TR> <TR><TD><B>Retail: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$retail"); ?>" SIZE=40></TD></TR> <TR><TD><B>Special: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$special"); ?>" SIZE=40></TD></TR> <TR><TD><B>Special2: </B> </TD><TD><INPUT TYPE="text" NAME="siteurl" VALUE="<?php echo("$special2"); ?>" SIZE=40></TD></TR> <TR><TH COLSPAN=2><P><INPUT TYPE="submit" name="submit" VALUE="Update Link"></P></TH></TR> </TABLE> </FORM> <?php } mysql_close($cid); ?> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/49405-solved-unable-to-update-from-php-script/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 1, 2007 Share Posted May 1, 2007 You may need to select a database before performing any queries. Link to comment https://forums.phpfreaks.com/topic/49405-solved-unable-to-update-from-php-script/#findComment-242124 Share on other sites More sharing options...
rebeat Posted May 1, 2007 Author Share Posted May 1, 2007 You may need to select a database before performing any queries. the database ($db) is "dbname" and the table is "products", executed as mysql_db_query($db,"$SQL",$cid); i also tried mysql_select_db($db, $cid); but sadly that didn't help. i'm still lost. :-\ really hope i get some progress, ive been days now on this issue. Link to comment https://forums.phpfreaks.com/topic/49405-solved-unable-to-update-from-php-script/#findComment-242169 Share on other sites More sharing options...
bubblegum.anarchy Posted May 1, 2007 Share Posted May 1, 2007 oh - ok... Clicking the [update Link] button on the link provided produced the following page 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 'special2 = '' WHERE id =' at line 1 UPDATE products SET title = '', description = '', retail = '', special = '' special2 = '' WHERE id = $id does not appear to be set anywhere. Link to comment https://forums.phpfreaks.com/topic/49405-solved-unable-to-update-from-php-script/#findComment-242177 Share on other sites More sharing options...
rebeat Posted May 1, 2007 Author Share Posted May 1, 2007 I used $id=$_POST['id'] which found the id, i still have problems tho but i need to move on as it is a time sensitive issue. cheers. Link to comment https://forums.phpfreaks.com/topic/49405-solved-unable-to-update-from-php-script/#findComment-242367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.