lloydje Posted August 10, 2007 Share Posted August 10, 2007 I'm having some problems with the update syntax. I'm populating a form with data from a db, but when i change anything and then try to update it doesn't seem to work. There are no error messages, it just fails to do anything; Here's my code - thanks for any help; (at the top of the page) <?php $usr = "user"; $pwd = "pass"; $db = "community"; $host = "host"; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> (within the page) <? # processed when form is submitted back onto itself if ($REQUEST_METHOD=="POST") { # setup SQL statement $SQL = " UPDATE mn_upcomingEvents SET"; $SQL = $SQL . " eventName = '$eventName', "; $SQL = $SQL . " date = '$date', "; $SQL = $SQL . " time = '$time', "; $SQL = $SQL . " location = '$location' "; $SQL = $SQL . " travelInfo = '$travelInfo' "; $SQL = $SQL . " url = '$url' "; $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><strong>Link Updated</strong></P>\n"); } else { # display edit form (not post method) # setup SQL statement to retrieve link # that we want to edit $SQL = " SELECT * FROM mn_upcomingEvents "; $SQL = $SQL . " WHERE id = $id "; # execute SQL statement $ret = mysql_db_query($db,$SQL,$cid); # retrieve values $row = mysql_fetch_array($ret); $eventName = $row['eventName']; $date = $row['date']; $time = $row['time']; $location = $row['location']; $travelInfo = $row['travelInfo']; $url = $row['url']; ?> <FORM NAME="fa" ACTION="editEvent.php" METHOD="POST"> <INPUT TYPE="hidden" NAME="id" VALUE="<?php echo("$id"); ?>"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Event Name</td> <td><input name="eventName" type="text" value="<?php echo("$eventName"); ?>"/></td> </tr> <tr> <td>Date</td> <td><input name="date" type="text" value="<?php echo("$date"); ?>"/></td> </tr> <tr> <td>Time</td> <td><input name="time" type="text" value="<?php echo("$time"); ?>"/></td> </tr> <tr> <td>Location</td> <td><input name="location" type="text" value="<?php echo("$location"); ?>"/></td> </tr> <tr> <td>Travel Info</td> <td><input name="travelInfo" type="text" value="<?php echo("$travelInfo"); ?>"/></td> </tr> <tr> <td>URL</td> <td><input name="url" type="text" value="<?php echo("$url"); ?>"/></td> </tr> </table> <INPUT TYPE="submit" VALUE="Update Link"></form> <?php } mysql_close($cid); ?> Thanks again. Lloyd Quote Link to comment Share on other sites More sharing options...
fenway Posted August 20, 2007 Share Posted August 20, 2007 Not sure why you're quoting your sSQL variable, echo it and see what it says. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.