Jump to content

[SOLVED] Login code problem


yddib

Recommended Posts

Hi,

The code I have for login works if the user is in the database however it returns a blank screen rather than the else statement if they enter an incorrect name. This is the code I have so far:

 


 

<?php

$user = htmlentities($_POST['user']);

$pass = htmlentities($_POST['pass'])

?>

 

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">

<head>

<title>You are Being redirected</title>

<!--<meta http-equiv="Refresh" content="3; URL=next.html">-->

</head>

 

 

<body>

<?php

mysql_connect("host", "username", "password") or die(mysql_error());

//connects to the blacknight server

 

 

mysql_select_db("our database");

//selects the database

 

 

$result = @mysql_query("SELECT f_name from gradinfo where email ='".$_POST["user"]."' and pass = '".$_POST["pass"]."'");

if (!$result)

 

{

echo "Login unsuccessful";

}

 

while ($row = mysql_fetch_array($result)) {

echo "Thank you for logging in,". $row['f_name']."<br/>Please click here to continue if your browser does not redirect you.";

}

 

 

 

 

?>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/121377-solved-login-code-problem/
Share on other sites

The $result checking doesn't do anything, it will just check if $result is a resource. You should have:

 

<?php
$user = mysql_real_escape_string($_POST['user']);
$pass = mysql_real_escape_string($_POST['pass']);
$results = mysql_query("SELECT f_name FROM gradinfo WHERE email='$user' AND pass='$pass'");
if(mysql_num_rows($results) == 1){
     echo 'You logged in. Yeah';
     //the other code
} else{
     echo 'Incorrect. Roar.';
}
?>

 

Side note: You may consider hashing the password with sha1() or md5().

Thanks very much for ye're help. We got it working using:

 

 

<?php

mysql_connect("host", "username", "password") or die(mysql_error());

//connects to the blacknight server

 

 

mysql_select_db("db1");

//selects the database

 

 

$result = @mysql_query("SELECT f_name from gradinfo where email ='".$_POST["user"]."' and pass = '".$_POST["pass"]."'");

if (mysql_num_rows($result) == 0)

{

echo "Incorrect username or password.";

}

else

{

while ($row = mysql_fetch_array($result))

{

echo "Thank you for logging in, ". $row['f_name'].".<br/>";

}

}

?>

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.