Best Web Designs Of the World Forums  

Go Back   Best Web Designs Of the World Forums > PROGRAMMING FORUMS > PHP Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 08-21-2008, 10:10 PM   #1 (permalink)
Member
 
Join Date: Feb 2008
Posts: 28
Default Sessions in php and mySQL?

No one seems to know how to do this.. and I NEED to know how to do this.

On my site, the person registers, they login.

As soon as they click login after entering their email and password.
It grabs their data from the members database, and pretty much logs them in.
In order to keep them logged in basically, I of course would start a session.

i'm not that great with sessions.. i know how to set a variable on one page in a session, start a session on the next page, and read the variable..

so if i name the variable 'name' and make it equal to 'Jack', and read the variable on the next page, "Jack" will show up.

okay.. but i'm not trying to do that because if someone logs in.. they're not always going to be Jack.. they're going to be wahetver they entered their name as when they first registered to become a member.

So..

here.. look at the code i'm using..

on the login.php page, that's where the enter their email and password to login, which gets sent to the login2.php page.

login2.php
--------------
<?php
include("config.php");

$tbl_name1="registered_members";

$match = "select id from $tbl_name1 where email = '".$_POST['email']."'
and password = '".$_POST['password']."';";

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);

if ($num_rows <= 0) {
echo "Sorry, there is no email $email with the specified password.<br>";
echo "<a href=login.php>Try again</a>";
exit;
} else {

session_start();
$_SESSION['name'] = $name;

include("index2.php");
}
?>

it includes config.php in which is what starts mysql ordeal.
it grabs the id's from the registered memebers table "email" and "password" and it basically confirms that they're there..

then after that.. i start my session to keep them logged in.

you can see how i started my session.

you can then see that they're redirected (basically) to index2.php [which for now is the members area until i can fix my problem]

i now have a page called logged.php, the coding for it is:

<?php
session_start();
echo $_SESSION['email']
?>


and on index2.php [the supposed redirect page[members area]]
i have "Welcome <?php include("logged.php");?>

so that it continues the session from the login2 page and comes up with "Welcome 'users name'"

okay.. now see.. that doesn't work.
i'm basically telling you what my idea and my goal is.. but that's not working.

i tried using the whole:
select id from $tbl_name1 where name

so that it'll call from the same table.. but then i get an error.

so i tried to go without it, and in the starting session, i replaced both "name"s with "email" so that maybe it would say "Welcome 'users email'" in which it doesn't do that... but it atleast comes up with index2 without giving me an error.. but it just says "Welcome" and that's it..

what do i do?

how do i have a user enter their email and password to login, and once done, have them get redirected to the members area [index2.php] and have it say "Welcome 'their name'"

how does it grab the name they entered during registration from the database in the process of login them in with their email and password..

does ANYONE know?!?!
sorry, logged.php is
<?php
session_start();
echo $_SESSION['name']
?>

i accidentally put 'email'
Jack is offline   Reply With Quote
Reply


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

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



All times are GMT. The time now is 05:41 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.