hola gente del foro, primero digo q soy un novato en php..
bueno tengo este codigo y me da un error al ejecutar la consulta pero no se porq, alguien me ayuda??
Código PHP:
<?php
if (strlen($_POST['logout']) > 0)
{
session_destroy();
}
ob_start();
$host="localhost";
$username="user";
$password="pass";
$db_name="database";
$tbl_name="table";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
if (strlen($myusername) > 0 || strlen($mypassword) > 0)
{
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
if (mysql_num_rows(mysql_query("SELECT * FROM '$tbl_name' WHERE user = '$myusername' and pass = '$mypassword'")))
{
$_SESSION['loggedin'] = 1;
echo "Entraste!!";
}
else
{
echo "Usuario o clave incorrecta";
}
}
ob_end_flush();
?>
<form name="login" method="post" action="index.php">
Usuario:
<input type="text" name="username"> <br>
Password:
<input type="password" name="password"><br><br>
<input type="submit" value="Loguear">
</form>
el error q me da este codigo es:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\U\index.php on line 30
alguien sabe porq?