(Added [code]...[/code] tags ~ MOD)

Hello everyone! I'm new in this forum.

I'm having a problem with my coding : when I execute the code below >>

<?php
include "inc/inc.koneksi.php";
include "inc/fungsi_hdt.php";

function anti_injection($data){
  $filter = mysql_real_escape_string(stripslashes(strip_tags(htmlspecialchars($data,ENT_QUOTES))));
  return $filter;
}
$username= anti_injection($_POST['username']);
$pass	 = anti_injection($_POST['password']);
#$pass = anti_injection($_POST['password']);
// pastikan username dan password adalah berupa huruf atau angka.
if (!ctype_alnum($username) OR !ctype_alnum($pass)){
//  echo "Sekarang loginnya tidak bisa di injeksi lho.";
?>
<script>
	alert('Sekarang loginnya tidak bisa di injeksi lho.');
	window.location.href='index.php';
</script>
<?php
}else{
	$login	=mysql_query("SELECT * FROM user WHERE user='$username'");
	$ketemu	=mysql_num_rows($login);
	if ($ketemu>0){
		$r		=mysql_fetch_array($login);
		$pwd	=$r['pass'];
		if ($r['blokir'] == 'Y'){
			salah_blokir($username);
			return false;
		}
		if ($pwd==$pass){
			sukses_masuk($username,$pass);
		}else{
			session_start();
			$salah =1;
			$_SESSION['salah']=$_SESSION['salah']+$salah;
			if ($_SESSION['salah']>=3){
				blokir($username);
			}
			salah_password();
		}
	}else{
		salah_username($username);
	}
}
?>

After that this error come out 😀
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sdm\cek_login.php on line 23

please advice me... 😕

It means the query was unable to be processed for some reason, so the mysql_query() call returned FALSE; so you need to do some debugging to find out why. E.g.: some temporary code:

$login	=mysql_query("SELECT * FROM user WHERE user='$username'");
if($login == false) {
  die("<pre>Query failed: ".mysql_error()."</pre>");
}

And, of course, you really should not be using the old MySQL extension, which has been deprecated for years, and instead using the MySQLi extension or perhaps the PDO extension, but that's a separate issue. 🙂

    ALWAYS check the result of a query operation for errors before attempting to use the query result.

      Write a Reply...