I have made a simple login and registration system (http://dak.esy.es/login/), and would like to retrieve other information from the same row in the MySQL database. Currently, only the username is saved (as $_SESSION['username']
), and this is what is entered on the login page. On the database, the data I want to be saved is id
, fullname
and email
- preferably in the same format as the username ($_SESSION['(name here)']
). I already have a file to connect to the database called db.php
. If anyone could provide the code I would be greatly pleased.
The code on my login.php
page is:
<?php
require('db.php');
session_start();
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
$username = $_POST['username'];
$password = $_POST['password'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
//Checking is user existing in the database or not
$query = "SELECT * FROM `users` WHERE username='$username' and password='".md5($password)."'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
if($rows==1){
$_SESSION['username'] = $username;
header("Location: ./index.php"); // Redirect user to index.php
}
else{
echo "<div class='form'><br/><h3>Username or password incorrect.</h3><br/>Click here to <a href='login.php'>try again</a></div>";
}
}
?>
Many thanks.