RE: [PHP] How to do a dynamic UPDATE SET

From: Date: Tue, 02 Oct 2001 00:15:29 +0000
Subject: RE: [PHP] How to do a dynamic UPDATE SET
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-69512@lists.php.net to get a copy of this message
Nope, still no go. Removing the single quotes stops PHP from updating the fields with $set's literal "$fieldname", but still doesn't update the record with the value (or anything). =============== CODE =============== if ($submit) { // if there is an ID, then it's an update if ($id) { $comma = ""; for ($i = 1; $i < $columns; $i++) { $fld = mysql_field_name($fields, $i); $set .= $comma."$fld=$".$fld; $comma = ", "; } $set .= " "; echo $set, "<p>"; // run SQL against the DB $sql = "UPDATE events SET what=$what WHERE id=$id"; echo $sql, "<p>"; $result = mysql_query($sql); } echo "<span class=adminnormal>Record updated"; } =============== OUTPUT =============== lang=$lang, record=$record, date=$date, what=$what, link=$link, location=$location, details=$details UPDATE events SET lang=$lang, record=$record, date=$date, what=$what, link=$link, location=$location, details=$details WHERE id=1 Record updated =============== ...Rene --- Rene Fournier renefournier@yahoo.com > -----Original Message----- > From: Vincent [mailto:vincent@smedinga.nl] > Sent: Monday, October 01, 2001 5:49 PM > To: php-general@lists.php.net > Subject: RE: [PHP] How to do a dynamic UPDATE SET > > > | The result: PHP updates the values of lang, record, date, what > (etc.) to > | [LITERALLY] $lang, $record, $date, etc--NOT the values of those fields > | submitted by the form. I'm kinda lost as to what to do... Any > | suggestions?? > > Ow yea, little mistake of mine, sorry. > I think removing the single quotes should do the trick. > > Vincent > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#69512) next »