Jump to content

log in system not working


conan318

Recommended Posts

does not redirected to  login_success.php also does not throw up wrong username or password message. gives no errors and all i get is a blank screen on the checklogin.php. is there something im missing?

 

 

login.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<? 
session_start();
require "database.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; " />
<title>Untitled Document</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div class="content">
<div class="header">
<img src="banner.png" />
</div>
  <div class="login">
    <form name="form1" method="POST" action="checklogin.php">
      
      Username
      
        <input name="myusername" type="text" id="myusername">
      <br />
      Password
        <input name="mypassword" type="password" id="mypassword">
      <br />
      
        <input type="submit" name="Submit" value="Login">
        
      
    </form>
</div>
</div>
</body>
</html>

 

 

checklogin.php

<? 

mysql_connect("localhost", "", "")or die("cannot connect"); 
mysql_select_db("main")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=md5($_POST["mypassword"]);

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM main.users WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count==mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername']
$_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword']
$_SESSION["country"] = $country;
$_SESSION["state"] = $state;




header("location: login_success.php");

else {
echo "Wrong Username or Password";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/243820-log-in-system-not-working/
Share on other sites

still just getting a blank screen also noticed i had $count=mysql_num_rows($result);

Have you got error reporting enabled? Speaking of handling errors. Your not bothering to check your query even works before using it's result.

do i use the or die to check if the query worked?


<? 

mysql_connect("localhost", "admin", "admin")or die("cannot connect"); 
mysql_select_db("main")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=md5($_POST["mypassword"]);

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT username,password FROM main.users WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername']
$_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword']
$_SESSION["country"] = $country;
$_SESSION["state"] = $state;
}



header("location: login_success.php");

else {
echo "Wrong Username or Password";

}
?>

still the same problem... where does the ELSE come from?

change this:

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername']
$_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword']
$_SESSION["country"] = $country;
$_SESSION["state"] = $state;
}
header("location: login_success.php");
else {
echo "Wrong Username or Password";
}

 

to this:

 

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername']
$_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword']
$_SESSION["country"] = $country;
$_SESSION["state"] = $state;
        header("location: login_success.php");
}else {
echo "Wrong Username or Password";
}

still just getting a blank page.. i just tested one of other pages and manged to get an error to throw up the error  handling is on. but im still getting a blank a page with no errors. is there  something wrong with my query maybe... the database name is main and the table is called users with a username and password field in the table.

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION["myusername"] = $myusername; //copy $myusername to $_SESSION['myusername']
$_SESSION["mypassword"] = $mypassword; //copy $mypassword to $_SESSION['mypassword']
$_SESSION["country"] = $country;
$_SESSION["state"] = $state;
        header("location: login_success.php"); // is the call header meant to be here like this? looks right to me
}else {
echo "Wrong Username or Password";
}

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.