Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

sessions and cheek box in php please help cheers.

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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Can you explain a little better... when you say "the user goes back to the page"... using the back button or your navigation?

Share this post


Link to post
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



Share this post


Link to post
Share on other sites
[code]<?php

echo '<input type="radio" name="radio1" value="radio1_value" '

if (!empty($_SESSION['radio1'])) echo 'checked="checked" ';

echo '/>';

?>[/code]

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


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

Share this post


Link to post
Share on other sites

×

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.