stublackett Posted September 9, 2008 Share Posted September 9, 2008 Hi, I've got a huuuuuuuuuuge form posting multiple values into a page titled "order.php" I just need to collect some of the data for an SQL Insert when I say a huge form, It has 29 fields of which 26 of them can potentially be filled in by the user My question is how do I collect the forms' post values instead of constantly repeating code like this : <?php $sendertitle = $_POST['sendertitle']; $senderforename = $_POST['senderforename']; $sendersurname = $_POST['sendersurname']; $senderaddress = $_POST['senderaddress']; $senderaddress1 = $_POST['senderaddress1']; $sendertown = $_POST['sendertown']; $sendercounty = $_POST['sendercounty']; $sendertelephone = $_POST['sendertelephone']; $senderemail = $_POST['senderemail']; //Number of people change to Integer Value $numberofpeople = $_POST['os']; ?> Is there a nice easier way round it? Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/ Share on other sites More sharing options...
redarrow Posted September 9, 2008 Share Posted September 9, 2008 put them all in an array then post that array nothink elese........ Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/#findComment-637363 Share on other sites More sharing options...
verdure Posted September 9, 2008 Share Posted September 9, 2008 you could use a code like this if ($_POST) { extract($_POST); } this will extract all the post variables. After which you could insert with a query like this $insertQuery = "INSERT INTO table VALUES ( '$variable1', '$variable2', '$variable3' "; make sure you are sending the right variables into the correct fields in the table (order of the variables). Also be careful while inserting numbers, they would not need ' '. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/#findComment-637365 Share on other sites More sharing options...
redarrow Posted September 9, 2008 Share Posted September 9, 2008 make sure to use mysql_real_escape_string as well Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/#findComment-637366 Share on other sites More sharing options...
stublackett Posted September 9, 2008 Author Share Posted September 9, 2008 you could use a code like this if ($_POST) { extract($_POST); } this will extract all the post variables. After which you could insert with a query like this $insertQuery = "INSERT INTO table VALUES ( '$variable1', '$variable2', '$variable3' "; make sure you are sending the right variables into the correct fields in the table (order of the variables). Also be careful while inserting numbers, they would not need ' '. Hope this helps. The extract($_POST) Works a treat.... Thanks! The Query is inserting the data, But having issues with the numbers, How do I present that data back? My SQL Inser Command is : $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail) values ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty','$sendertelephone','$senderemail')"; The field that is effected at the moment is sendertelephone Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/#findComment-637373 Share on other sites More sharing options...
verdure Posted September 9, 2008 Share Posted September 9, 2008 Thats kool This is the first time i have given a technical suggestion ... you do not use the '$sendertelephone' if it is a numeric data type. you just enter the value as $sendertelephone. Guess that should fix it. Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/#findComment-637375 Share on other sites More sharing options...
stublackett Posted September 9, 2008 Author Share Posted September 9, 2008 Still no joy The telephone number seems to be missing the zero, Its not a major loss if it isnt there as the data is going to be re-presented back anyways I've got the SQL Insert Query now as : $sql = "INSERT INTO $db_table(experiencename,sendertitle,senderforename,sendersurname,senderaddress,senderaddress1,sendertown,sendercounty,sendertelephone,senderemail) values ('$description','$sendertitle','$senderforename','$sendersurname','$senderaddress','$senderaddress1','$sendertown','$sendercounty',$sendertelephone,'$senderemail')"; Link to comment https://forums.phpfreaks.com/topic/123403-solved-collecting-post-over-and-over-again/#findComment-637378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.