Hello everyone. First, a little about me. I started off web development in .Net (C#) and found it to be not suiting my style. Then I moved on to PHP and instantly fell in love with it. I've been practicing it for the last 40-45 days and have covered up most of the topics with ease. I'm also past the beginner mode in AJAX and Jquery, which are awesome by the way. As a result, I'm in a position where I would not need to be spoon fed the solutions (I hope) xD
Back to topic, I'm currently working on a project which contains 3 forms - all huge forms in terms of number of fields. On a average, each form contains around 18-20 fields. Now the problem I'm facing is to decide how to hold and use the field values of the form with minimum effort. In other words, I'm looking for the best practices to follow while dealing with long forms. I can go the old fashioned way of storing each value in a variable and then put those values in the database with an equally long Mysql query.
So far, the closest I've come is to use the foreach loop. With this, I'm able to grab the field values in one line of code :
foreach($_POST as $key=>$value)
$$key = mysql_real_escape_string($value)
Now I'm wondering if there is any similar approach to store the values in the database with writing a small query instead of typing:
mysql_query("INSERT INTO tablename (col1, col2, col3, col4...., col18) VALUES ('$val1','$val2','$val3......','$val18')");
Now that is a huge query for a form with 18 fields. I'm assuming using OPPS approach in PHP will ease that for me, but I'm not that far yet. I'm yet to start learning the OPPS concept in PHP.
In a nutshell, I've accomplished holding the values of a form with a single line of code using foreach loop, but is there a similar way to make it store in the database without having to type in all the column names of the table as well as the variable names?
Thanks and Regards,