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
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";

}
?>

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.