Jump to content


Photo

problems showing a database entry


  • Please log in to reply
1 reply to this topic

#1 siphi

siphi
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 18 December 2003 - 10:38 PM

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 sessionsession_start();// checks if userid and pwd are entered in formif ($username && $password) { // connects to the database$Connect = mysql_connect("localhost", "root", "password"); // selects the database usermysql_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 existsif (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 sessionsession_register("valid_user, password, email");} } ?>


<?php// checks that valid_user and password are registeredif (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.

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 18 December 2003 - 10:52 PM

Never mix $_SESSION and session_register()

http://www.phpfreaks...pic.php?t=10842

See this link

http://www.phpfreaks...opic.php?t=7632

Also there are lot of posting available about sessions have a look at them.
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users