Okay I went into myadmin (sql) part of it. i typed in the
the sql statement that I have remarked out. it did not except it. so I went and tried
SELECT * FROM users WHERE username = "$username" AND password ="$password"
I got this as a response:
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0005 sec)
sql query
SELECT *
FROM users
WHERE username = "$username"
AND PASSWORD = "$password"
LIMIT 0 , 30;
here is my code again with the change. I'm still getting the blank screen. so who knows.
?php
ini_set('display_errors', 1); // change to 0 for production version
error_reporting(E_ALL);
$success = true;
$message ='';
//print_r($_POST);
$username = $_POST['username'];
$password = $_POST['password'];
if($username =='') {
$success = false;
$message .= 'Please enter your username';
}
if($password == '') {
$success = false;
$message .= 'Please enter your password';
}
if($success) {
$db = mysql_connect('localhost', 'root', '********');
if($db) {
mysql_select_db("TREllis");
//$sql = "SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "'";
$sql = 'SELECT * FROM users WHERE username = "$username" AND password ="$password"';
$res = mysql_query($sql) or die(mysql_error());
if ($res && mysql_num_rows($res) >0){
if(($username == "admin") && ($password == "admin")) {
$row = mysql_fetch_assoc($res);
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $row['username'];
header("location: adminpage.php");
} else {
if(mysql_num_rows($res) > 0){
$row = mysql_fetch_assoc($res);
$_SESSION['logged_in'] = true;
$_SESSION['username'] = $row['username'];
header("location: news.php");
}else{
$success = false;
$message .= "Incorrect login<br>";
}
}
}
}
}
?>
form: I have made mistakes on the form before. but I don't think I did it this time since it worked before.
<?php
// require ("dbcon.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
<form action="loginval.php" method="post" name="login">
<table>
<tr>
<td>Username: </td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td></td>
<td align="center"><input type="submit" name="login" value="Login"/></td>
</tr>
</table>
</form>
</html>