Jump to content

session


ShaolinF

Recommended Posts

Hi,

I have the 3 following radio boxes and I want to add whichever one is selected into a session, how would I do this ?

 

<input type="radio" name="group2" value="Water"> Water<br>

<input type="radio" name="group2" value="Beer"> Beer<br>

<input type="radio" name="group2" value="Wine" checked> Wine<br>

Link to comment
Share on other sites

switch($_POST['group2']){
   case 'Water':
       $_SESSION['group2']=$group2;
       break;
   case 'Beer':
       $_SESSION['group2']=$group2;
       break;
   case 'Wine':
       $_SESSION['group2']=$group2;
       break; }

 

edit: forgot the breaks

Link to comment
Share on other sites

isset checks if the variable is set.

Ex:

 

$submit = $_POST['submit'];
//check if the form has been submitted
if(isset($submit)){
echo "The form has been submitted!";
}else{
//otherwise if the form hasn't been submitted, display the form 
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
echo "<input type=\"submit\" value=\"Submit\" name=\"submit\">";
}

 

What that script does is it checks if a user has pressed the submit button. If they have pressed the submit button (it is checked using isset), it displays the message 'The form has been submitted'. If they have not clicked submit, it will show them the form. By checking if the form has been submitted using isset, this prevents the script from automatically being run when someone visits the page.

 

PHP isset

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.