Hello, I have form with lots of fields - The users fill them and when he submit the forum the data collected with $_POST , get check, and if it all ok - insert into the DB. Is there any fast way to collected all the user data and insert it into the DB instead of doing: $va1 = $_POST['var1']; $va2 = $_POST['var2']; $va3 = $_POST['var3']; .... .. . INSERT INTO table_name (var1, var2, var3,...) VALUES (var1, var2, var3,...) PHP: ?
I think the code above is perfect, if someone will point out any other way to speed up things, then it would be helpful for me too
Check in the separate connected file (check.php), if all is carried out to add in a database include "check.php"; if($check==true){ mysql_query("INSERT INTO `table_name` (var1, var2, var3,...) VALUES ('".$_POST['var1']."', '".$_POST['var2']."', '".$_POST['var3']."',...)"); } PHP:
Just an observation based on form filling... when were dealing with lots and lots of data for collection, we usually do it in steps, ie: 1, 2, and finish... from the users end filling in little bits of information rather then quite a lot in one go, makes the process mentally seem faster.
Actually as caching in database is a term that has absolutely different meanings, I would call your question as about minimizing code. If you have passed all security checks on the incoming data and you are secure to use $_POST (if you confirm), then: mysql_query( 'INSERT INTO `table_name` (`'. implode('`, `', array_keys($_POST)).'`) VALUES ("'.implode('","', $_POST).'");'); Code (markup): or to get all variables created quickly, you can simply extract the array extract($_POST); // = $var1 $var2 .... automatically created, use them Code (markup):
i always get my post data to a variable and then pass it through a mysql_real_escape_string($user) and then place the new filtered variable in your mysql connection string This is done to prevent injection into your database a very important step im my opinion