Hello,
I have a members area on my website. I'm trying to check if a user with a specific username and id has logged in, and then echo a string of text on page B (members area page) if its them.
The user logs in on page A (login page). Their details are then carried over to page B (members area page) using session variables... then on page B (members area page) I try to use a mysql query to make sure the username matches the one that is entered on page A (login page), and the id of that username is 1. If both conditions are met, it should echo the string 'Hello Mike click here for more info'
But if only one condition is met, it should'nt echo anything!
Trouble is it's not working! Can anyone help?
Displayed below is the code on page B (members area page):
<?php
@session_start();
$host="host"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="dbname"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
$con = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Session variable containing username carried forward from previous page
$myusername = $_SESSION['myusername'];
// query to check that checks to see username entered exists in database, and matches record with id of 1
$result="SELECT username FROM members WHERE username = ". $myusername. " AND id = ". 1 ." limit 1";
mysql_query($result, $con);
// Takes correct username, checks it against session variable stored in variable $myusername. IF condition is true, echo string of text.
if($result = $myusername){
//display
echo'Hello Mike click here for more info';
}
?>
Cheers,
Paul.