Jump to content

[SOLVED] lol,,, now my login script stopped working


Reaper0167

Recommended Posts

if your username is not in the database,, the error  comes up saying that your not registered. but for the usernames that i know are in the database, it won't take me to the success page.

<?php

// server and database variable information
$host = "----------";
$username = "-----------";
$password = "------------";
$db_name = "----------";
$tbl_name = "-----------";

// connects to server and database
mysql_connect("$host", "$username", "$password") or die("Could not connect.");
mysql_select_db("$db_name") or die("Could not find database");

// username and password sent from form
$username = $_POST['username'];
$password = $_POST['password'];

// protect MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

// check username and password
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count = mysql_num_rows($result);

// sending user to homepage or giving them log in error
if ($count == 1) {
    header("location: home.php");
    //echo "You are now logged in.";
    //$message = "You are now logged in.";
    //header("location: index.php?error=" . urlencode($message));
} else {
    //echo "This username is not registered. Please register first.";
    $message = "This username is not registered. Pleaser register first.";
    header("location: index.php?error=" . urlencode($message));
}

?>

Maybe because you use two different variables?

 

$username = mysql_real_escape_string($username);

$password = mysql_real_escape_string($password);

 

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

 

Either use $myusername or $username for both, same with $mypassword and $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.