So been looking on the web for some time and have attempted to follow examples...
What I want to do is get the user to login and then a session to start which I have and have tested and it does work, however I'm having trouble getting the username or any other item of data from the database.
The user logs in with the username and password. They are then directed to another page with this code...
<?php
session_start();
if(!session_is_registered(user_name));
$con = mysql_connect("****","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("****", $con);
$result = mysql_query("SELECT * FROM fyp_users;");
$first_name = $_SESSION['first_name'];
$_SESSION['views']=200;
header('location:../profile.php');
?>
The Session views thing was just a test and that works find and displays the number when the user is logged in. I have then attempted to do the first_name session.
This is the page that it then redirects too...
<?php
$con = mysql_connect("****","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("****", $con);
?>
<?php
session_start( );
//$result = mysql_query("SELECT * FROM fyp_users;");
?>
Some HTML....
<?php
echo "Pageviews=". $_SESSION['views'];
echo "Welcome=" . $_SESSION['$first_name']
?>
How it's not displaying the name, I know no if it's an easy fix or not, can anybody help me?
--------------------------------------------UPDATE---------------------------------------
HTML FORM
<div class="login">
<form id="login" method="post" action="includes/checklogin.php">
<p>Login</p>
<p>Username</p>
<input name="user_name" id="user_name">
<p>Password</p>
<input name="password" id="password" type="password">
</br>
<input type="submit" name="Submit" value="Login">
</form>
</div>
<!--<img src="images/logo.png" alt="The Community">-->
</div>
checklogin.php
<?php
$con = mysql_connect("****","***","***");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("****", $con);
$user_name=$_POST['user_name'];
$password=$_POST['password'];
$user_name = stripslashes($user_name);
$password = stripslashes($password);
$user_name = mysql_real_escape_string($user_name);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM fyp_users WHERE user_name='{$user_name}' and password='{$password}'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1) {
session_register("user_name");
session_register("password");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
login_success,php
<?php
session_start();
if(!session_is_registered(user_name));
$con = mysql_connect("***","****","****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Finds database
mysql_select_db("*****", $con);
$result = mysql_query("SELECT * FROM fyp_users;");
$first_name = $_SESSION['first_name'];
$password = $_SESSION['password'];
$_SESSION['views']=200;
header('location:../profile.php');
?>
profile.php
<?php
session_start();
echo "Pageviews=". $_SESSION['views'];
echo "Welcome=" . $_SESSION['first_name']
?>
Thanks James