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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MARINp
Forum Newbie
Posts: 1
Joined: Sat Oct 20, 2012 1:08 pm

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

Post 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.
Last edited by Benjamin on Sat Oct 20, 2012 1:23 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
Post Reply