Re: updateable database 2nd question

From: Date: Fri, 20 Jun 2003 19:22:04 +0000
Subject: Re: updateable database 2nd question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-152346@lists.php.net to get a copy of this message
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 dread@texas.net -- 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.

« previous php.general (#152346) next »