Jump to content

1st Time Trying a Session


amsterdam

Recommended Posts

Hi,

 

I am trying to construct one script with a form that registers sessions with a radio button, a check box and a dropdown select.

I have never used a session before and I am just try to echo out the session values. Any help would be greatly appreciated.

Here is what I have so far. I believe this form is ready to add a session?

 

<body>

<form action="session.php" method="post">

Enter Your Name<br/>

<input type="text" name = "name"><br/>

Do you have a purpose here?<br/>

<input type="checkbox" name="purpose" value="YES" />YES<br />

Your Gender?<br/>

<input type="radio" name = "gender" value="male">Male<br/>

<input type="radio" name = "gender" value="female">Female<br/>

Select your favorite programming language.<br/>

<select name="language" >

<option value="">------------</option>

<option value="php">PHP</option>

<option value="javascript">JavaScript</option>

</select>

<input type = "submit" value = "Remember Me!">

</form>

Register your FULL session!</body>

</html>

Link to comment
Share on other sites

In sessions.php simply do:

<?php
// always call session_start() before using sessions
session_start();

// add all $_POST data to session
$_SESSION = $_POST;

?>
Data saved to session!

<a href="session2.php">Display Session</a>

Now create another file, call this session2.php and add the following code:

<?php
session_start();

echo 'Your name is <b>' . $_SESSION['name'] . '</b> and you are <b>' . $_SESSION['gender'] . '</b><br />';

echo 'You have <b>' . ( ($_SESSION['purpose'] == 'YES') ? 'a' ? 'no' ) . '</b> purpose here<br />';

echo 'Your favourite programming language is <b>' . $_SESSION['language'] . '</b>';

?>

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.