note 100375 added to function.mysql-query

From: Date: Tue, 12 Oct 2010 12:00:59 +0000
Subject: note 100375 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-173154@lists.php.net to get a copy of this message
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"; } } //------------------------------------------------------- ---- Server IP: 69.147.83.197 Probable Submitter: 213.55.95.196 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/100375 Del: integrated -- https://master.php.net/note/delete/100375/integrated Del: useless -- https://master.php.net/note/delete/100375/useless Del: bad code -- https://master.php.net/note/delete/100375/bad+code Del: spam -- https://master.php.net/note/delete/100375/spam Del: non-english -- https://master.php.net/note/delete/100375/non-english Del: in docs -- https://master.php.net/note/delete/100375/in+docs Del: other reasons-- https://master.php.net/note/delete/100375 Reject -- https://master.php.net/note/reject/100375 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173154) next »