Page 1 of 1

Hewbiee help (Warning: mysql_num_rows() expects... )

Posted: Sat Oct 20, 2012 1:12 pm
by MARINp
Hello. First time trying to build a login register form

Here is what error I get "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Files\gingerphp\login.php on line 61"

and my code is :

Code: Select all

<?php
session_start();




?>

<html>
	<head>
    	<title>Login</title>
     </head>
     
     
<body>
<h1>Log in </h1>

<form action="login.php" method="post">
<table >
	<tr>
    	<td>Username</td>
        <td><input type="text" name = "username" />
        </td>
    </tr>
    <tr>
        <td>Keyword</td>
        <td><input type="keyword" name = "keyword" />
        </td>
	 </tr>
     <tr>
     	<td colspan = "2"><input type="submit" name="submit" value="Login" />
        </td>
      </tr>

</table>

</form>
<?php

include 'config.php';
mysql_connect($host,$user,$keyword) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
 
 if ($_POST['submit']) {
	
	 //get the form data
	 
	 $myusername = ($_POST['username']);
	 $mykeyword = ($_POST['keyword']);
	 
	 //check that all fields are filled in
	 
	 if ( (!$myusername)|| (!$mykeyword) ) {
	 echo 'Please fill in all fields';
	 exit;}
	 
	 //check the form`s database
	
	$sql = " SELECT * FROM {$usertable} WHERE username='{$myusername}' AND keywork= '{$mykeyword}' ";
	$result = mysql_query($sql);
	$count = mysql_num_rows($result);
	
	//check if user did this
	
	if ($count == 1) {
		$_session['username'] = $myusername;
		$_session ['keyword'] = $mykeyword;
		$_userrecord ['userrecord'] = mysql_fetch_assoc($result);
		echo 'You have been logged in sucessfully, please click <a href="account.php"</a> here to continue';
	}
 }

?>



</body>

</html>
If anyone would be kind enough to check and point me in the right direction!!
Can`t figure out why I get the error.

Re: Hewbiee help (Warning: mysql_num_rows() expects... )

Posted: Sat Oct 20, 2012 6:30 pm
by requinix
99% of the time the "boolean given" means that your query failed due to a syntax error. And here that's exactly the case: there's a typo in your query.