Jump to content

sessions and cheek box in php please help cheers.


redarrow

Recommended Posts

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 only
test.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]
Link to comment
Share on other sites

can it be done becouse i am going mad i tried this but no joy

i 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]
Link to comment
Share on other sites

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 from

cheers

the 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



Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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