Current location: Hot Scripts Forums » Programming Languages » PHP » Cookies with mysql


Cookies with mysql

Reply
  #1 (permalink)  
Old 01-30-07, 12:18 PM
djburnage djburnage is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Cookies with mysql

Hi
I have a simple login script. At the moment it stores the cookies with just the username and password that the user specified But i would like it to also store the group that the user is in, in the cookie. The group is specified along side the username and password collom in a mysql table called "login". So im guessing i would need some sort of mysql query.
I was wondering if anyone can tell me how to do this.
The bit bellow is only part of the script

PHP Code:

$username $_POST['username'];

$password $_POST['password'];
if (
$username=="") {
die(
"You must enter a username!");}
if (
$password=="") {
die(
"You must enter a password!");}
$query "SELECT * FROM login WHERE username ='$username'";
$result mysql_query($query) or die('Query failed: ' mysql_error());
$data mysql_fetch_array($resultMYSQL_ASSOC);
$truepass $data['password'];
if (
$truepass == $password) {
$cookie $username;
setcookie("user",$cookie);
setcookie("pass",$truepass); 
thanks
chris

Last edited by djburnage; 01-30-07 at 12:21 PM. Reason: more info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-30-07, 12:41 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
as you allready use a query that will select all data from the login table, you just have to select the "group" value in the $data array:
PHP Code:

$group $data["group"];

setcookie("group"$group); 
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-30-07, 01:19 PM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
Also,

You might want to consider using $_SESSION rather than cookies. $_SESSION sets a single cookie on the client side with a session id, but you can store anything you want (well mostly) in it just as though it were a persistent associative array.

All you have to do is put session_start() at the top of any program you want to access the data.
__________________
"Things are difficult only while you don't understand them."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-31-07, 04:49 PM
djburnage djburnage is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for your help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Useful MySQL Resources ptesone Database 30 02-23-11 09:28 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
MySql Labyrinth moron Database 4 02-22-08 03:46 AM
UPDATE: MySQL Auto Backup & Export v1.1 Beyonder General Advertisements 2 03-21-05 03:05 PM


All times are GMT -5. The time now is 11:41 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.