note 63160 deleted from control-structures.foreach by bjori

From: Date: Tue, 14 Mar 2006 22:26:48 +0000
Subject: note 63160 deleted from control-structures.foreach by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-105820@lists.php.net to get a copy of this message
Note Submitter: http://www.vainternet.co.uk Reason: bad code ---- A friend of the UPDATE query maker, this generates insert queries and is used in the same way <? if ($_POST){ //change the table name for your table $query = "INSERT INTO table ("; //Set this to the number of fields you have $a = 2; //this is the counter, so you don't get submit buttons in the query $b = 0; $c = 0; foreach ($_POST as $key => $value) { if ($b != $a){ $$key = addslashes(trim($value)); $query.= " " . $key . " "; $b++; } if ($a == $b){ $query.=" "; }else{ $query.=","; } } //Add data $query.=")VALUES("; foreach ($_POST as $key => $value) { if ($c != $a){ $$key = addslashes(trim($value)); $query.= "'" . $value . "'"; $c++; } if ($a == $c){ $query.=" "; }else{ $query.=","; } } $query.=")"; //Remove this line after you have debugged print $query; if ($result = MYSQL_QUERY($query)){ print "success"; }else{ print "not success"; } } ?> http://www.vainternet.co.uk

« previous php.notes (#105820) next »