xxreenaxx1 Posted March 14, 2011 Share Posted March 14, 2011 I have foreach method. This displays the choices that are selected and the value inside them as 1. The method is shown below. I am printing these with the name(choice1, choice2, choice3, choic4) and the value. If there is a value then it prints 1. Now my problem is I want to INSERT them into my database. if it prints choice1, choice2 then value 1 must be entered into choice1 and choice2 inside the database. I am not sure how to do this. can someone help me. foreach ($_POST["choice"] as $question => $answer) { if($answer == NULL) { $val=0; } else{ $val = 1; } echo "choice id: $question. value: $val <br />"; Quote Link to comment https://forums.phpfreaks.com/topic/230636-foreach-method/ Share on other sites More sharing options...
sasa Posted March 15, 2011 Share Posted March 15, 2011 can you print_r ($_POST) and post results Quote Link to comment https://forums.phpfreaks.com/topic/230636-foreach-method/#findComment-1187615 Share on other sites More sharing options...
xxreenaxx1 Posted March 15, 2011 Author Share Posted March 15, 2011 I got it sorted. Thanks anyways Quote Link to comment https://forums.phpfreaks.com/topic/230636-foreach-method/#findComment-1187694 Share on other sites More sharing options...
xxreenaxx1 Posted March 15, 2011 Author Share Posted March 15, 2011 Nope, its not sorted. This is what I get when I print Array ( [Que_ID] => 5 [choice] => Array ( [1] => Array ( [0] => on ) [2] => Array ( [0] => on ) [3] => Array ( [0] => on ) [4] => Array ( [0] => on ) ) [submit] => submit ) Quote Link to comment https://forums.phpfreaks.com/topic/230636-foreach-method/#findComment-1187726 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.