Jump to content

Stream line $_POST


denoteone

Recommended Posts

I have 43 input  text boxes that I am going to name  box0 box1, box2 and so on. is there a trick I can use to assign them once I submit the form.  so that I don't have to do  $box_1 = $_POST['box1']; some sort of loop and then I am going to have to insert the values into a mySQL database.

 

Any help would be awesome.

 

 

Link to comment
https://forums.phpfreaks.com/topic/180441-stream-line-_post/
Share on other sites

if box[] is your HTML array, you could access each individual element like so

 

echo $_POST['box'][5];//the sixth text box

 

you could loop through the whole array like so

for ($i = 0; $i < count($_POST['box']); $i++){
echo $_POST['box'][$i];
}

//OR

foreach($_POST['box'] as $box){
echo $box;
}

Link to comment
https://forums.phpfreaks.com/topic/180441-stream-line-_post/#findComment-951961
Share on other sites

so would my code look something like this

if(isset($_POST['submit'])){

for($i = 0, $i <= 43,$i ++){
$box.$i = box[i];
}

}

 

Don't do that. What if one day you added another checkbox, or took one away? Chances are you won't find the error when you define 43 like that.

Link to comment
https://forums.phpfreaks.com/topic/180441-stream-line-_post/#findComment-951975
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.