On 20-Jun-2003 Matt Hedges wrote: > Thanks for the help. I now have the wine information displaying in text > boxes (below is the code that displays all the wines). > > Now I want anyone to be able to change the data in text box/s and hit > "update" and it change that field/s. > > Would it be something like > $sql = "UPDATE wines SET > Bodega='$Bodega',Name='$Name',Grape='$Grape',Year='$Year',Region='$Region' > ,S > ubRegion='$SubRegion' WHERE id='$id'"; ? > > How do I set it up with the submit, etc? >
//refetch the old row ... $qry="SELECT * FROM tbl WHERE id='" .$_POST['id'] ."'"; $r=mysql_query($qry); $row=mysql_fetch_array($r); // build list of just the changes unset($chgflds); foreach($row as $fld => $val) { if (isset($_POST[$fld]) && ($_POST[$fld] != $val)) { $chgflds[] = "$fld='" .$_POST[$fld] ."'"; } } // doit. $update='UPDATE tbl SET ' .implode(', ', $chgflds) ."WHERE id='" .$_POST['id'] ."'"; echo '<!--Debug :', $update, '-->'; mysql_query($update); ... Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php