phpretard Posted July 19, 2010 Share Posted July 19, 2010 I am working on an "online employment application". Consequently it has about 83 fields. Rather than $name=$_POST['name']; 83 times ... is there a way to get everything that is posted as an array and store it in a database accordingly? ("insert into apps ONE ARRAY") as opposed to: if (isset($_POST['application'])){ // put all into an array $_POST['FnameTxt']; $_POST['LnameTxt']; $_POST['AddressTxt']; $_POST['CityTxt']; $_POST['StateTxt']; $_POST['ZipTxt']; $_POST['CountryLst']; $_POST['EmailTxt']; $_POST['PhoneNum']; $_POST['FaxNum']; $_POST['desiredPosition']; $_POST['otherPosition']; $_POST['StartofWork']; $_POST['Employer']; $_POST['employerAddressTxt']; $_POST['From']; $_POST['To']; $_POST['Supervisor']; $_POST['Salary']; $_POST['Work']; $_POST['Reason']; $_POST['Employer2']; $_POST['employerAddressTxt2']; $_POST['From2']; $_POST['To2']; $_POST['Supervisor2']; $_POST['Salary2']; $_POST['Work2']; $_POST['Reason2']; $_POST['Employer3']; $_POST['employerAddressTxt3']; $_POST['From3']; $_POST['To3']; $_POST['Supervisor3']; $_POST['Salary3']; $_POST['Work3']; $_POST['Reason3']; $_POST['HSName']; $_POST['HSLocation']; $_POST['HSMajor']; $_POST['HSDiploma']; $_POST['HSYear']; $_POST['UnivName']; $_POST['UnivLocation']; $_POST['UnivMajor']; $_POST['UnivDiploma']; $_POST['UnivYear']; $_POST['UnivName1']; $_POST['UnivLocation1']; $_POST['UnivMajor1']; $_POST['UnivDiploma1']; $_POST['UnivYear1']; $_POST['TradeName']; $_POST['TradeLocation']; $_POST['TradeMajor']; $_POST['TradeDiploma']; $_POST['TradeYear']; $_POST['Q1']; $_POST['Q2']; $_POST['Q3']; $_POST['Q4']; $_POST['Q5']; $_POST['Q6']; $_POST['Q7']; $_POST['Q8']; $_POST['Q9']; $_POST['Q10']; $_POST['Q11']; $_POST['refName']; $_POST['occupation']; $_POST['refAddressTxt']; $_POST['refPhone']; $_POST['Relationship']; $_POST['Known']; $_POST['refName1']; $_POST['occupation1']; $_POST['refAddressTxt1']; $_POST['refPhone1']; $_POST['Relationship1']; $_POST['Known1']; $_POST['gender']; $_POST['ethnic']; $_POST['howrefered']; } // seems like a lot of redundant typing Any suggestions would be greatly appreciated. -Ant Quote Link to comment https://forums.phpfreaks.com/topic/208216-how-can-i-put-all-post-in-an-array-and-store-them/ Share on other sites More sharing options...
jamesxg1 Posted July 19, 2010 Share Posted July 19, 2010 The $_POST global is an array you just have to manipulate it correctly. foreach($_POST as $key => $value) { echo $key . ' - ' . $value . '<br />'; } James. Quote Link to comment https://forums.phpfreaks.com/topic/208216-how-can-i-put-all-post-in-an-array-and-store-them/#findComment-1088316 Share on other sites More sharing options...
bh Posted July 19, 2010 Share Posted July 19, 2010 Hi, I think you should starting with the forms structures. You use one form now for those datas. Rather you should use more forms (structured by logically isolated parts). You would to show over the users through the forms... Example: Personal details Human resources details ... Quote Link to comment https://forums.phpfreaks.com/topic/208216-how-can-i-put-all-post-in-an-array-and-store-them/#findComment-1088319 Share on other sites More sharing options...
Andy-H Posted July 19, 2010 Share Posted July 19, 2010 function SQLclean($val) { if (ctype_digit($val)) { return $val; }else{ return "'" . mysql_real_escape_string($val) . "'"; } } if (isset($_POST['submit'])) { unset($_POST['submit']); $fields = array_keys($_POST); $values = array_walk($_POST, 'SQLclean'); $query = "INSERT INTO tableName ( `" . implode('`,', $fields) . "` ) VALUES ( " . implode(', ', $values) ." )"; } Quote Link to comment https://forums.phpfreaks.com/topic/208216-how-can-i-put-all-post-in-an-array-and-store-them/#findComment-1088321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.