Jump to content


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


User not found.....

Recommended Posts

I have the following code:

header("Cache-control: private");

// Get MySQL Database information


// Make variables from the form

$Username = $_POST['userName'];
$Password = $_POST['passWord'];

// Remove HTML (if any)

$Username = strip_tags("$Username");
$Password = strip_tags("$Password");

// Remove escaped characters (if any)

$Username = stripslashes("$Usermame");
$Password = stripslashes("$Password");

// Connect to server and select database.

mysql_connect("$dbHost", "$dbUserName", "$dbPassWord")or die("Cannot connect to server!");
mysql_select_db("$dbName")or die("Cannot select Database!");

// Does the user exist?

$sql_user_check = 'SELECT * FROM users WHERE username="$Username"';
$result_name_check = mysql_query($sql_user_check);
$usersfound = mysql_num_rows($result_name_check);

// If the user doesn't exist, create error

if ($usersfound < 1) {
$error = "User $Username not found.";

// If the user does exist, continue with processing


// Check if the passwords match

    $sql_pass_get = 'SELECT * FROM users WHERE username="$Username"';
    $user_info = mysql_fetch_array(mysql_query($sql_pass_get));
  $encryptpass = $user_info['password'];

// If it doesn't match, note that and end
  if ($encryptpass != md5($PassWord)) {
    $error = "Invalid password.  Try again.";

// If it does match, let in and pass on info to session variables


        $_SESSION['userid'] = $user_info['userid'];
      $_SESSION['username'] = $user_info['username'];
      $_SESSION['password'] = $user_info['password'];


if (!$_SESSION['username']) {
echo "$error";



On index.php (login) l enter the username l entered into the MySQL database and it says user not found... I have gone into the MySQL database using phpmyadmin and the username is there.  So what is going on?



Share this post

Link to post
Share on other sites
$sql_user_check = 'SELECT * FROM users WHERE username="$Username"';

$username is taken as literal, as its in single quotes on the PHP-level


$sql_user_check = "SELECT * FROM users WHERE username=\"$Username\"";

Share this post

Link to post
Share on other sites


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.