How to echo it properly (wrong username and password) mysql

when type in wrong username and password and press submit it only display “1” instead of displaying "wrong username and password "

//query database to get information.
$query = mysql_query(“SELECT * FROM data_time WHERE username = '”.$username.“’ AND password = '”.$password."’ ")or die(mysql_close());
$res = mysql_num_rows($query)or die(mysql_close());

if ($res > 0){
$_SESSION[‘username’] = $_POST[‘username’];
header(‘Location: profile.php’);
die();

}else{
echo “Wrong username and password”;
die();
}

You can’t put a call to mysql_close() inside a call to die().

Are you aware that MySQL_* is obsolete and PDO is the recommended approach?

Do you need the “or die()” clause on the end of this? I haven’t seen it before.

$res = mysql_num_rows($query)or die(mysql_close());

I think it should read just

$res = mysql_num_rows($query);

thanks, it actually solved my problem.

Of course none of the mysql_ calls will work when the PHP version on the server is next upgraded as that interface was deleted from PHP earlier this month.

Yes, @Gandalf had already mentioned that so I didn’t want to labour the point. I can only assume OP is in charge of their server versions and will plan ahead to suit.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.