Jump to content

login page problom


gotenxds

Recommended Posts

hallo i cant seem to find whats worng with this login file i made that i include in my index page

 

i keep on geting the

"sorry, please enter your username and password to login" error while trying to log in with a valid username and password.

 

 

<?php 
require_once('db_login.php');

//the error massged

$Login_error = "" ;
//chacck if looged in, else check if trying to login
if (!isset($_COOKIE['User_Id'])){
  if (isset($_POST['submit'])){
  //connect to db
       $connection = mysql_connect($db_host, $db_username, $db_password);
   //grabing user enterd details
   $user_username = mysqli_real_escape_string($connection, trim($_POST['UserName']));
   $user_password = mysqli_real_escape_string($connection, trim($_POST['password']));
   if (!empty($user_username) && !empty($user_password)){
   $query = "SELECT User_Id, UserName FROM users WHERE UserName = '$user_username' AND ".
   "password = '$user_password'";
   $data = mysqli_query($connection, $query);
      if(mysqli_num_rows($data) == 1){
		//user name and pass are ok
		setcookie('User_Id', $row['User_Id']);
		setcookie('password', $row['password']);
		$home_url = 'http://' .$_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF']) . '/index.php';
		header('Location: ' . $home_url) ;
	  }
	    else{
		//worng username AND\OR password
		$Login_error ="the username or password are incorrect";	
		}
   }
     else{
		 //no username and'or password were enterd
		 $Login_error = "sorry, plz enter your username and password to login";
		 }

  }

}

?>

<?php
//if the cookie is empty show errormsg and form
if(empty($_COOKIE['User_Id']))
{ echo $Login_error ;
;
?>
<script type="text/javascript" >
               $(document).ready(function () {
                   $("#login").ready(function () {
                       $("#login").slideDown('slow');

                   });

               });


</script>
<div id="login" style="background-color:#09C;border:1px solid; width:100%; height:25px; display:none; margin-bottom:5px;">
         
         לא חבר באתר?
            <a href="/Register.php"><span style="color:#9C3; font-style:oblique;">הרשם</span></a>
            עכשיו!
          
            <form style="float:right" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
            
      <label>
   שם משתמש: <input type="text" id="UserName" name="UserName"/>
      </label>      
            

            
      <label>
   סיסמה: <input type="password" id="password"  name="password"/>
      </label>      
      
      <input type="submit" name="submit" value="התחבר" />
      
       
            </form>
  
                 
</div>

<?php } 
else{
?>

<div id="login" style="background-color:#09C;border:1px solid; width:100%; height:25px; display:none; margin-bottom:5px;">
         
שלום 
<?php echo $_COOKIE['UserName']; ?>
          
  
  
                 
</div>

<?php }?>

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/245721-login-page-problom/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.