Jump to content

sessions and variables


daneth1712

Recommended Posts

Hi,

 

Would anyone be able to tell me or advise me on how or if it is possible to take more than 1 variable in a script and add it to a session?

 

I need to be able to take 3 variables from a script and add them to a session so I can check them off against another form on the next page.

 

Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/167531-sessions-and-variables/
Share on other sites

Hi lynxus,

 

Thanks for your reply.

 

I think I know where I am going wrong here, I just dont know how to fix it.

 

Basically, I have a 3 field form that gets sent to the below page:

<?php



$name=($_POST['name']);
$email=($_POST['email']);
$country=($_POST['country']);

//send back to the activate page if called from other location or empty
if (!isset($name) || !isset($email) || !isset($country)){
header( "Location: activate.html" );
}
elseif (empty($name) || empty($email) || empty($country)) {
header( "Location: activate.html" );
}

include 'includes/config.php';
$connection = @mysql_connect($hostname, $adminuser, $adminpass)
or die(mysql_error());
$dbs = @mysql_select_db($database, $connection) or
die(mysql_error());


$sql = "SELECT * FROM userinfo WHERE name='$name' AND email_address='$email' AND country='$country'";
$result = @mysql_query($sql,$connection) or die(mysql_error());
$row = mysql_fetch_object($sql);
if ($result) {
while ($array= mysql_fetch_assoc($result)) {
session_start();
session_register('name', 'email', 'country');
header( "Location: activate_part2.php" );
}
}
else {
echo 'No results found.';}
?>

 

Now I am either going wrong with setting the sessions above, or in the 'start session' which is added at the top of each of the pages in the form....

 

<?php
//start the session
session_start();

$_SESSION['name'] = $_POST['name'];
$_SESSION['email'] = $_POST['email'];
$_SESSION['country'] = $_POST['country'];

if(session_is_registered('name', 'email', 'country')){
$name_id=$_SESSION['name'];
$email_id=$_SESSION['email'];
$country_id=$_SESSION['country'];
}
else{
//the session variable isn't registered, send them back to the activate page
header( "Location: activate.html" );
}
?>

 

I am getting redirected back to the activate.html page so I know the problem is how I have set the sessions.

 

Any pointers would be really helpful.

 

Thanks again!

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.