hey people im still working on my first project that users can register and just login the register page work preeeeety fine and good.
i have an index.php witch's where people will login and my base.php file that hold my database details
here is the code of the base.php
PHP Code:
<?php
session_start();
// DATABASE CONSTANTS
define("DB_SERVER","localhost");//it's better to leave it "localhost"
define("DB_USER","root");//The defult user "root:
define("DB_PASS","");//type ur database password if u have
define("DB_NAME","userslogin");//the database name u've setup
//the database connection
$connection = mysql_connect(DB_SERVER,DB_USER);
if(!$connection){
die("Database connection failed: " . mysql_error());
}
//select database
$db_select = mysql_select_db(DB_NAME, $connection);
if(!$db_select){
die("database selection failed:" . mysql_error());
}
?>
and here is the index.php file code
PHP Code:
<?php require_once("base.php"); ?>
<html>
<head>
<title>User Login</title>
</head>
<style>
body{background:#dbdbdb; margin:0; padding:0; font:'Verdana', Geneva, sans-serif;}
</style>
<link href="stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
<body>
<div id="box_outter">
<div id="box_bg">
<div class="header">
<img src="images/logo.gif" alt="Logo" class="logo">
<img src="images/bigman.jpg" alt="bigman" class="bigman">
</div>
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['username']))
{
?>
<p>Welcome back<?=$_SESSION['username']?>.</p>
<ul>
<li><a href="logout.php">Logout.</a></li>
</ul>
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$_SESSION['username'] = $username;
$_SESSION['LoggedIn'] = 1;
echo "<p>you now logged in successfully</p>";
echo "<meta http-equiv='refresh' content='=3;index.php' />";
}
else
{
echo "<p>this user dose not exist</p>";
}
}
else
{
?>
<div class="body">
<div class="login_box">
<h1 class="li-h"></h1>
<form action="index.php" method="post" class="login_box_out">
<input type="text" name="username" class="user_form" value="Username"
onfocus="if(this.value=='Username'){this.value=''};" onBlur="if(this.value==''){this.value='Username'};">
<input type="password" name="password" class="pass_form" value="password"
onfocus="if(this.value=='password'){this.value=''};" onBlur="if(this.value==''){this.value='password'};">
<input type="submit" name="login" class="login_btn" value=" ">
</form>
<a href="register.php" class="reg-link">Register</a>
</div>
</div>
<?php } ?>
</div>
</div>
</body>
</html>
<?php
mysql_close($connection);
?>
please take a good look to this index.php
i have in my database tow usernames the first one is {mohsen} and the second one is {test}
while i write in the tow forms the username and the password like this
{more details in the image}
while i click on login button i get "this user dose not exist"
like this {more details in the image}
my problem is that i have that username and password in my database and he can't found it can anyone please help me and tell me what is my fult in the code that made it get me the else statement
thanx for anyhelps