Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2005, 06:38 PM
Authorized User
 
Join Date: Jan 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to register a variable with session

Hi,

i was wondering if any one can help me? i have a logon form that asks the user for their username and password. upon clicking login a second form is displayed showing all their details from the database. how do i store their Account ID taken from the database in a session and carry it forward to third form where i insert it to a different table in the mysql db.

Thanks in advanced

Scoobie

 
Old March 18th, 2005, 11:00 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this something along the line of this: this is just a sample code, so you might want to give your hands a try.

//get the $username and $password from the field. you can try doing an md5 on the pass variable if thats how you saved it;
$query = "select * from users where username = '$username' AND password = '$password'";

and then you can use this to save it in the session variable:

$query2 = mysql_query($query);

while ($row = mysql_fetch_assoc($query2)){


$_SESSION['somename'] = $row['somenamefrommysql'];
$_SESSION['anothername'] = $row['someothernamefrommysql'];
}

that should save it in the session: make sure you start the session at the beginning the page by
session_start();

hope that helps...
post code if not working




----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
 
Old April 20th, 2005, 10:21 AM
Authorized User
 
Join Date: Jan 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much it works great

scoobie






Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Variable youyou_hym Dreamweaver (all versions) 4 January 20th, 2005 11:48 AM
Session variable anuradha80 General .NET 3 November 4th, 2004 12:39 AM
Session variable mrideout BOOK: Beginning ASP.NET 1.0 1 August 12th, 2004 07:01 PM
Session Variable mcdowell BOOK: Beginning ASP 3.0 5 June 20th, 2004 05:47 AM
Error with variable..maybe register globals codefinder Beginning PHP 1 November 19th, 2003 03:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.