redarrow Posted September 11, 2006 Share Posted September 11, 2006 Advance thank you.Can you kindly show me how to use sessions to keep the information that the user has pressed cheers.So if the user get a error meesage when that user goes back to the page the checkbox/radio is a kept value cheers.[code]<? Session_start();?><table width="550" align="center" border="4" bordercolor="black"><td align="center"><br><b><font color="blue">Please let users no the <font color="red">payment method</font> you accept</font></b> <table width="525" align="center" border="4" bordercolor="black"> <td align="center"> <p><b><font color="blue">Paypal</font></b> <br> <input type="radio" name="paypal1" value="yes" checked> yes <input type="radio" name="paypal1" value="no"> no<br> <br> <b><font color="blue">Cheek</font></b> <br> <input type="radio" name="cheek" value="yes" checked> yes <input type="radio" name="cheek" value="no"> no <br> <br> <b><font color="blue">Bank transfer</font></b> <br> <input type="radio" name="bank_transfer" value="yes" checked> yes <input type="radio" name="bank_transfer" value="no"> no <br> </p> <td align="center"> <p><b><font color="blue">Postal order</font></b> <br> <input type="radio" name="postal_order" value="yes" checked> yes <input type="radio" name="postal_order" value="no"> no <br> <b><font color="blue"><br> </font></b> <b><font color="blue">Cash via post</font></b> <br> <input type="radio" name="cash" value="yes" checked> yes <input type="radio" name="cash" value="no"> no <br> <b><font color="blue"><br> </font></b> <b><font color="blue">Credit card</font></b> <br> <input type="radio" name="credit_card" value="yes" checked> yes <input type="radio" name="credit_card" value="no"> no <br> </p></td> <br> </table></td></table>[/code]example onlytest.php[code]<?php session_start();$paypal1=$_SESSION['paypal1']=$paypal_yes;$paypal1=$_SESSION['paypal1']=$paypal_no;echo "<a href='test_result.php'>cheek the session for radio box</a>";?>[/code]test_result.php[code]<?php session_start();?><form action="test.php method="POST"><input type="radio" name="paypal1" value="<?php echo $paypal_yes;?>" checked>yes <input type="radio" name="paypal1" value="<?php echo $paypal_no;?>">no<br><input type="submit" name="submit" value="send"></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/ Share on other sites More sharing options...
redarrow Posted September 11, 2006 Author Share Posted September 11, 2006 can it be done becouse i am going mad i tried this but no joyi have tried for hours please help [code]<?php session_start();echo "<a href='url2.php'>cheek the session for radio box</a>";?>[/code][code]<?php session_start();$no="no";$yes="yes";if($paypal1=="yes"){$_SESSION['yes']=$yes;}elseif(paypal1=="no"){$_SESSION['no']=$no;}?><form action="url.php" method="POST"><input type="radio" name="paypal1" value="<?echo $yes;?>" checked>yes <input type="radio" name="paypal1" value="<?echo $no;?>">no<br><input type="submit" name="submit" value="send"></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89772 Share on other sites More sharing options...
ober Posted September 11, 2006 Share Posted September 11, 2006 Can you explain a little better... when you say "the user goes back to the page"... using the back button or your navigation? Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89782 Share on other sites More sharing options...
redarrow Posted September 11, 2006 Author Share Posted September 11, 2006 I am trying to get the radio box to keep its vaule with a session.so if the user goes to another page the radio box keeps it value of yes or no there will be a link for the user to go back to the page they came fromcheersthe whole idear is when a user uses the radio box to ansaw a quistion the radio box keeps it's value incase the user has an error as the code i am programming is a registartion and quistions.if the user gets the ansaw wrong then i need the current radio box with the users information Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89785 Share on other sites More sharing options...
Jenk Posted September 11, 2006 Share Posted September 11, 2006 [code]<?phpecho '<input type="radio" name="radio1" value="radio1_value" 'if (!empty($_SESSION['radio1'])) echo 'checked="checked" ';echo '/>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89790 Share on other sites More sharing options...
redarrow Posted September 11, 2006 Author Share Posted September 11, 2006 jenk are you drunk becouse how will that code you provided me help cheers. Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89795 Share on other sites More sharing options...
obsidian Posted September 11, 2006 Share Posted September 11, 2006 what jenk is trying to get at, i think, is the basic premise behind radio buttons. i would modify his code slightly, though, because we're dealing with radio buttons and not checkboxes. you've got to see if the $_POST variable holds the current radio button's value and then "check" the one that is corresponding. so, take this basic example and see if it gives you some understanding:[code]<form name="test" action="" method="post"><?php$options = array(1,2,3,4,5,6,7,8,9,10);foreach ($options as $option) { echo "<input type=\"radio\" name=\"myTest\" value=\"$option\""; if (isset($_POST['myTest']) && $_POST['myTest'] == $option) echo ' checked="checked"'; echo " /> $option<br />\n";} ?><input type="submit" name="submit" value="Remember!" /></form>[/code]hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89801 Share on other sites More sharing options...
redarrow Posted September 11, 2006 Author Share Posted September 11, 2006 obsidian thank you for the code m8 but i need a slitly more advance way.obsidian can you see my problam i got the first post shows the form i am working with i need to get some how the value of yes or no echoed within a page but with sessions becouse if there an error then the user does not have to do the radio agin as the session will keep the value.i can keep the value but i need to keep the value within a session. Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89807 Share on other sites More sharing options...
Jenk Posted September 11, 2006 Share Posted September 11, 2006 for christ sake man! Assign the variable to the session array, then use isset() or empty() to verify if there is a value, if there is echo checked="checked" to pre-select the radio button.Really, we are prepared to provide you with food, put it on your plate, hell even feed it to you, but YOU must be the one to chew! Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89814 Share on other sites More sharing options...
redarrow Posted September 11, 2006 Author Share Posted September 11, 2006 well i can not get it going so can you do the above form so i can learn from it sorry for the not no cheers.[b]give me a proper example as the one above does not work for me ok.try to give an example from my code as posted from first post thank you.[/b] Quote Link to comment https://forums.phpfreaks.com/topic/20384-sessions-and-cheek-box-in-php-please-help-cheers/#findComment-89815 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.