Jump to content

problems showing a database entry


siphi

Recommended Posts

Hi I\'m trying to get the users email address to be shown on the login page when he logs in. But it\'s not working. I\'m also trying to put it into a session. Heres the code.

 

<?php

// start the session

session_start();

// checks if userid and pwd are entered in form

if ($username && $password) 

{ 

// connects to the database

$Connect = mysql_connect("localhost", "root", "password"); 

// selects the database user

mysql_select_db("database");

// selects all from database user where userid equals form entry uid and password equals form entry pwd

$sql = " SELECT * FROM user WHERE username = \'$username\' AND password = PASSWORD(\'$password\')";  

$result = mysql_query($sql); 

// checks user exists

if (mysql_num_rows($result) > 0) 

{ 

while($row = mysql_fetch_array($result))

{$row[email] = $email;}

// sets up variables

$valid_user = $username;

$password = $password;

// registers variables into session

session_register("valid_user, password, email");

} 

} 

?> 

 

 

<?php

// checks that valid_user and password are registered

if (session_is_registered("valid_user, password, email")) 

{ 



$_SESSION[\'valid_user\'] = $_POST[\'username\'];

$_SESSION[\'password\'] = $_POST[\'password\'];



echo "<center><br><br>You are logged in: $valid_user <br>Your password: $password <br>Your email: $email<br>"; 

echo "<center><a href="index.php?c=11">Continue to members area</a><br>";

echo "<center><a href="testsetings.php">Change your password</a><br>";

echo "<center><a href="logout.php">Log out</a><br>";} 



else 

{ 

if (!isset($username)) 

{ echo "<center>Either you have not registered or your username and or password is incorrect."; } 

else 

{ echo "<center>You are not logged in. <br>"; } 

echo "<center><a href="index.php">Login</a><br>"; } 

?>

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.