Jump to content

[SOLVED] post issue


gish

Recommended Posts

hi phpfreaks

 

 

I am creating a questionnaire for my website but I am having trouble the script. Each question has three options that will be posted 1,2,3 1 meaning yes, 2 meaning no, and 3 unsure. When it gets submitted to the next page I have to sort the amount of 1, 2 and 3's. Is  there and easier way other than using the if statement for every post variable  or can I use a loop statement?

 

below is what I have so far. what I want to know is there a way to get the

if ($_POST[business] == 1){
  $Yes = $Yes + 1;
}
elseif ($_POST[business] == 2){
$No = $No + 1;
}else{
   $Unsure = $Unsure + 1;
}

echo $_POST[business];
echo $_POST[performance];
echo $_POST[budget];
echo $_POST[structure];
echo $_POST[goals];
echo $_POST[customer];

Link to comment
https://forums.phpfreaks.com/topic/140426-solved-post-issue/
Share on other sites

<?php
$Yes = 0;
$No = 0;
$Unsure = 0;
$fields = array('business','performance','budget','structure','goals','customer');

foreach($fields as $k)
{
	switch($_POST[$k])
	{
		case 1:
			$Yes++;
				break;
		case 2:
			$No++;
				break;
		case 3:
			$Unsure++;
				break;
	}
}
?>

 

Something like this make it a little shorter for ya??

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/140426-solved-post-issue/#findComment-734959
Share on other sites

yeah, if your checkboxes/radio boxes all have the same name, add [] to the end of the name such as

<input type="radio" name="answer" value="yes">
<input type="radio" name="answer" value="no">
<input type="radio" name="answer" value="unsure">

 

the $_POST['answer'] or $_GET['answer'] variable would be passed to your script...and you can check to see what that value equals...

 

 

edit: [mis-read...]

Link to comment
https://forums.phpfreaks.com/topic/140426-solved-post-issue/#findComment-734963
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.