Woodburn2006 Posted November 21, 2007 Share Posted November 21, 2007 i am creating arrays from a form, when i pass the arrays into another page to use them it works fine if i am putting the arrays into a DB stright away. but what i wanted to do is pass the arrays into another page so that the user can double check that the info they entered is correct and so that the system can check for any errors. i have managed to achieve this but when i try passing the arrays on again it syays that there is an error in the parameters used for the foreach() loop that i am using. has anyone got any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/78286-using-arrays/ Share on other sites More sharing options...
wildteen88 Posted November 21, 2007 Share Posted November 21, 2007 How are you passing your array of data to the next page? The best way to pass temporary data easily and efficiently without using a database is sessions. Then once your script has processed all the data and there is no errors you can insert it in the the database at the final stage. Quote Link to comment https://forums.phpfreaks.com/topic/78286-using-arrays/#findComment-396168 Share on other sites More sharing options...
Woodburn2006 Posted November 22, 2007 Author Share Posted November 22, 2007 i am passing them using $_POST, i pass it to the second page and it displays all of the data but then when i try passing the same variables to the final page it says it is invalid. how would i use sessions to do it? Quote Link to comment https://forums.phpfreaks.com/topic/78286-using-arrays/#findComment-396397 Share on other sites More sharing options...
Stephen68 Posted November 22, 2007 Share Posted November 22, 2007 Are you just displaying the text for them to look at? hmm.. How are you putting all the form fields into the array? On the second page are you just looping through the $_POST? How are you passing them in $_POST[] to the third page? I would just put the form field and value into two arrays and store them into a sessions. foreach ($_POST as $field => $value) { addslashes($field); addslashes($value); $names[] = "$field"; $values[] = "'$value'"; } //Pop off the submit feild and value and then Implode the into a string //that will be passed in the SQL statment. Notice the string is imploded //with the "," array_pop($values); array_pop($names); $_SESSION['name'] = $names; $_SESSION['values'] = $values Then you can just loop through the values array to show the user what they had put in. If they click whatever you have (button maybe) to confirm the info you and just use the session to insert the data in the DB. My form field names are the same as my DB fields most times so all I do is this. $names = $_SESSION['name']; $values = $_SESSION['values']; $name_string = implode(", ", $names); $value_string = implode(", ", $values); // Build the SQL statment to pass to MySQL $query="INSERT INTO jobs ($name_string) Values ($value_string)"; Not sure if this helps at all or even if I have this right, doing to from the top of my head and it is not tested code. I'm sure somebody else will be able to reply better later on maybe. Hope that I have helped at least a little Stephen Quote Link to comment https://forums.phpfreaks.com/topic/78286-using-arrays/#findComment-396464 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.