Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/78286-using-arrays/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/78286-using-arrays/#findComment-396168
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/78286-using-arrays/#findComment-396464
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.