Jump to content

echo "$_SESSION['name']


Matthew Herren

Recommended Posts

Ok i'm trying to create a page after a form is submitted so the user can review and edit their posted variables. I'm not sure about the best way to do this but i'm trying to save them in a session then echo them. Like This:

<php
/session start
session_start();

// variables
session_register('name');
session_register('last');
session_register('mi');
session_register('hp');
session_register('cp');
session_register('work');
session_register('email');
session_register('add');
session_register('add2');
session_register('city');
session_register('state');
session_register('zip');
session_register('password');


//finally, let's store our posted values in the session variables
$_SESSION['name'] = $_POST['name'];
$_SESSION['last'] = $_POST['last'];
$_SESSION['mi'] = $_POST['mi'];
$_SESSION['hp'] = $_POST['hp'];
$_SESSION['cp'] = $_POST['cp'];
$_SESSION['work'] = $_POST['work'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['add'] = $_POST['add'];
$_SESSION['add2'] = $_POST['add2'];
$_SESSION['city'] = $_POST['city'];
$_SESSION['state'] = $_POST['state'];
$_SESSION['zip'] = $_POST['zip'];
$_SESSION['password'] = $_POST['password'];


?>
<HTML>
<HEAD>
</HEAD>
<body>
<php echo"$_SESSION['name']"?>
</body>
</HTML>

Is this the best way, or is there a better way??

Link to comment
https://forums.phpfreaks.com/topic/176339-echo-_sessionname/
Share on other sites

first off, you do not need to use session_register.  In fact, it's already deprecated and being removed as of php6.

 

2nd...what exactly is your overall goal here?  I'm not really seeing the point of having the user enter in editable stuff in a form, only to turn around and let them edit it again... perhaps you can explain what you're trying to do on a more "top" level?

 

Regardless though, what you have is technically right, minus the session_register which technically works but is superfluous and deprecated.

 

edit:

 

oh just noticed also you have the session var wrapped in quotes when you echo it.  That is not necessary either.

Link to comment
https://forums.phpfreaks.com/topic/176339-echo-_sessionname/#findComment-929434
Share on other sites

Archived

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

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