SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 31st, 2004, 12:31 PM
Natt_Brown Natt_Brown is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Boro, England
Posts: 1 Natt_Brown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy PHP MySQL Session Variables

Hey all,
having a spot of bother with my lame ass Final Project and was wondering if any of you bigger brains out there could help me as i left my spare bigger brain at home.

I'm creatin a members only section for an existing site. once users log in they will be able to view the publications that they subscribe to. so what i would like to do is save their usernames and passwords or User_ids as session variables so that as they continue thru the site it will show information relevant to them from the database. if you catch my drift.
now the problem is. i can't get the damn variables out there!!

my site currently works around 2 php pages, one with the form to fill in and the other that it posts to which then links to the main intro page. so here goes

* Please post code blocks within the appropriate [ code ] or [ php ] formatting tags *

PHP Code:
<?php
session start
();
?>
<html>
<head>
<title>Listing 15.7 User Login Form</title>
</head>
<body>
<H1>Login Form</H1>
<FORM METHOD="POST" ACTION="listing15.8.php">
<P><STRONG>Username:</STRONG><BR>
<INPUT TYPE="text" NAME="username"></p>
<P><STRONG>Password:</STRONG><BR>
<INPUT TYPE="password" NAME="password"></p>
// this is settin the variable for the sessions from the values entered in the text box
    <?php
    $_SESSION
[username];
    
$_SESSION[password];
    
?>
<P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login"></P>
</FORM>
</body>
</html>

then it posts to this page
<?php
//check for required fields from the form
if ((!$_POST[username]) || (!$_POST[password])) {
    
header("Location: listing15.7.php");
    exit;
}

//connect to server and select database
$conn mysql_connect("blah""blah""blah") or die(mysql_error());
mysql_select_db("blah",$conn)  or die(mysql_error());

//create and issue the query
$sql "select f_name, l_name from auth_users where username = '$_POST[username]' AND password = password('$_POST[password]')";
$result mysql_query($sql,$conn) or die(mysql_error());

//get the number of rows in the result set; should be 1 if a match
if (mysql_num_rows($result) == 1) {
   
//if authorized, get the values of f_name l_name
   
$f_name mysql_result($result0'f_name');
   
$l_name mysql_result($result0'l_name');


   
//prepare message for printing, and user menu
   
$msg "<P>Welcome to the Erinys News Site $f_name $l_name </p>";
   
$msg .= "<ul><li><a href=\"main.html?<?php print SID;?>\">secret page</a></ul>";
   } else {
   
//redirect back to login form if not authorized
   
header("Location: listing15.7.php")

;
   exit;
}
?>
<HTML>
<HEAD>
<TITLE>Listing 15.7 </TITLE>
</HEAD>
<BODY>
<? print "$msg"?>
</BODY>
</HTML>

which should in turn open this page 

<?php
session start
();
?>
<html>
<head>

</head>
<body>
<p> blah blah blah </P>
<?php
    
print "<ul> <li> $_SESSION[username]\n <li> $_SESSION[password]\n<?UL>\n";
?>
</body>
</html>


if any of you can help i would just adore you for the rest of my long legged life.
Thanks
Natt

Reply With Quote
  #2  
Old January 31st, 2004, 04:15 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Try this to register session variables:

PHP Code:
 session_register('username'); 
$_SESSION['username'] = $username


Then simply echo $_SESSION['username'];

in the future, try putting [ php][/php ] tags around your code (Without the spaces)... this will colour-ize your syntax

Reply With Quote
  #3  
Old February 2nd, 2004, 09:48 AM
Anna4 Anna4 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 Anna4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Don't use session_register: my (admittedly old) PHP manual says:
"Caution
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). "

I think Natt's problem was just that he missed out the quotes
$_SESSION['username'];
$_SESSION['password'];

Reply With Quote
  #4  
Old February 6th, 2004, 08:31 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Anna's right... Those functions were used prior to the super global arrays... To start a session, you can simply create your first session object, and the session should automatically register itself. If I'm wrong in this, please do correct me.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > PHP MySQL Session Variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway