note 100375 deleted from function.mysql-query by danbrown

From: Date: Tue, 12 Oct 2010 16:11:18 +0000
Subject: note 100375 deleted from function.mysql-query by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173165@lists.php.net to get a copy of this message
Note Submitter: sendmillo at gmail dot com (Minilik Tesfaye) ---- Hi all, here is a function to insert a record into a table that are collected from a form. :) What is special here is, this function can automatically collect the POSTed values of the form and creates an array. Therefor, you can simply use this array without writing anything about the names or ids of the form elements. Besides, This function can also construct an automatic SQL command to insert a record in a table. If you got any comment, please mail me Minilik T. Enjoy!. //----------------------------------------------------------- function add_new($table){ $all=array_keys($_POST); $q="insert into $table values(NULL,"; for($i=0;$i<count($_POST);$i++){ $q=$q."'".$_POST[$all[$i]]."',"; } $q=$q."'".$_POST[$all[$i]]."')"; //echo $q; $add_res=mysql_query($q)or die(mysql_error()); if($add_res){ echo"$table inserted"; } } //-------------------------------------------------------

« previous php.notes (#173165) next »