Jump to content

$_POST & Array ?? I think


simplyrichard

Recommended Posts

I'm having a litte trouble trying to think out the best process to collect a large number of items checkmarked. I will later have to insert a database row depending on each item selected here is an example of what I am trying to do.

 

List of open positions (Select all positions that you would like to apply for)

 

Office Manager

House Keeping

HR Administrator

Director of IT

 

Lets say the user selects three of the four above.

 

I call the $_POST['jobs_selected']; and now I have an array if I am not mistaken. How do I use the information within $_POST['jobs_selected']; I will need to insert each item selected into a different table. The user can select many jobs to apply to at once which could be different departments, I want to insert the application in each of the department's tables I have created. Therefore I need to know each job ID that the user selected. How would I do this?

 

Thanks for your help.

 

Richard  ;D

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/130288-_post-array-i-think/
Share on other sites

Assuming that your HTML is correct where:

name="jobs_selected[]" <-- Don't forget the square brackets

 

foreach($_POST['jobs_selected'] as $job){
     // Do a db query
     // Do anything else you want
     // Each value now is referred to by using $job
     echo 'Job Selected: '.$job.'<br />';
}

Link to comment
https://forums.phpfreaks.com/topic/130288-_post-array-i-think/#findComment-675706
Share on other sites

Here is an example of what I am trying to do which is not work...

 

setcookie("jobs_selected", $_POST['apply'], time()+3600);

foreach($_COOKIE["jobs_selected"]; as $key=>$value)
    {
    // and print out the values
    echo $key." ".$value.' <br />';
    }

Link to comment
https://forums.phpfreaks.com/topic/130288-_post-array-i-think/#findComment-675748
Share on other sites

after the setCookie command, the cookies are not available until the next page load....

 

that aside, i don't see the need for cookies here. once the info is submitted you want to store them in the tables right? do you have an INSERT commands written yet? how are the tables setup?

Link to comment
https://forums.phpfreaks.com/topic/130288-_post-array-i-think/#findComment-675772
Share on other sites

I'm not ready to store them into a table. I want to store them until I need them. For me to use them I have to make sure an applicant has filled out an application and of course is logged in. I thought a cookie would work well because I have no information about the user until after they have registered or logged in.

Link to comment
https://forums.phpfreaks.com/topic/130288-_post-array-i-think/#findComment-675776
Share on other sites

Like this?

 

$_SESSION['jobs'] = $_POST['apply'];

foreach($_SESSION['jobs'] as $key => $value){
     // Do a db query
     // Do anything else you want
     // Each value now is referred to by using $job
     echo $key." ".$value'<br />';
}

 

yes, that should work, just make sure you do a session_start() at the beginning of the script. again, this assumes you don't want to use the data right away.

Link to comment
https://forums.phpfreaks.com/topic/130288-_post-array-i-think/#findComment-675800
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.