Jump to content


Photo

Retaining variables accross pages


  • Please log in to reply
5 replies to this topic

#1 yrrahxob

yrrahxob
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationKaty, Texas

Posted 17 September 2006 - 02:56 PM

I am building my own web site and on the main page, there is an option to login to a users' account if they so desire.  This is not a requirement.  After they login, they can browse through products and and then to the shopping cart.  When they are ready to checkout, they are presented with a form asking for name and address and other information.  What I want to do is when the form is presented and they are logged in, the form will be populated with the information retrieved when they logged in.

below is the validation/login script I am working on.  I want to keep the values of the array $user_info during the entire session and I have register_globals disabled.  Someone please help.

<?php

function validate_user($user_email, $user_password){

$row=array();

$q = db_query("SELECT ss_first_name, ss_last_name, ss_email, ss_phone, ss_address_1, ss_address_2, ss_city, ss_state, ss_zip_1, ss_zip_2 FROM ".USER_TABLE." WHERE ss_email='$user_email' AND ss_password='$user_password'") or die (db_error());
$row = db_fetch_row($q);
return $row;

}

if(isset($_POST["login_submitted"])){
$user_info=validate_user($_POST["user_email"], $_POST["user_password"]);
}

?>

Harry R. Box
[br]We must all hang together or we shall surely hang separately.
[br]
[br]A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 17 September 2006 - 03:00 PM

In order to ratin variables across pages you could use sessions.

Put
session_start()
before anything is output (eg on the top of the page) and define the variables like $_SESSION['something']. You would then be able to call it on another page (which has ran session_start() too) as $_SESSION['something'].

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 03:01 PM

lookup sessions


quick example.

test.php

<?php session_start();

$name="redarrow";

$name=$_SESSION['name']=$name;

echo"<a href='test_result.php'>please see my name</a>";

?>

test_result.php
<?php session_start();

echo"Hello there my name is $name";

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 17 September 2006 - 03:11 PM

I don't think that would work

This will work:

test.php
<?php
session_start();
$_SESSION['name'] = "something";
echo"<a href='test_result.php'>please see my name</a>";
?>

test_result.php
<?php
session_start();
echo "Hello there my name is {$_SESSION['name']}";
?>


#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 03:17 PM

mine does work i think your getting confused as i set the session with the varable name.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 17 September 2006 - 07:09 PM

<?php session_start();

$name="redarrow";

$name=$_SESSION['name']=$name;

echo"<a href='test_result.php'>please see my name</a>";

?>


Why on earth would do
$name=$_SESSION['name']=$name
for? I see no logic in that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users