Hi,
could someone tell me what the correct syntax is to check is a user exists in my database.
I got a login page and when user enters username and password i need it to check if they exist obviously in database and if so re-direct them to the page i specify else tell them login details don't exist.
Anyone be able to help me please?
thank you, genieuk
So, in essence, you want a login script?
$config_basedir = "http://www.yoursite.com";
$user = mysql_real-escape_string($_POST['email']);
$password = mysql_real-escape_string($_POST['password']);
$loginsql = "SELECT * FROM main WHERE email = '$user' AND password = '$password'";
$loginres = mysql_query($loginsql);
$numrows = mysql_num_rows($loginres);
if($numrows == 1){
$loginrow = mysql_fetch_assoc($loginres);
$_SESSION['SESS_LOGGEDIN'] = 1;
$_SESSION['SESS_NAME'] = $loginrow['username'];
//If login is correct
header("Location: " . $config_basedir . "/index.php");
}
else {
//if login is incorrect
header("Location: " . $config_basedir . "/login.php?error=2");
}
Then you can put this where to show the errors
<?php
switch($_GET['error']) {
case "1":
echo "<font color='#FF0000'>You must be logged in.</font>";
break;
case "2":
echo "<font color='#FF0000'><strong>Incorrect username/password</strong></font>";
break;
}
?>