Jump to content


Photo

Script doesnt work


  • Please log in to reply
2 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 14 September 2006 - 08:39 AM

Hello, I need some help with this script. I have been working on it for a few hours and cant get the output i wanted.

I keep getting this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\login_form.php on line 30


Heres the script:
<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
if (!isset($_SESSION['login']) && !isset($_POST['user'])) {
    // if no data, print the form
?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
       Username:<input type="text" name="user"><br>
	   Password:<input type="text" name="pass"><br>
        <input type="submit" name="submit">
    </form>
<?php
}
else if (!isset($_SESSION['login'])) {

	include('connect.php');
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
	$user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']);
	$pass = empty($_POST['pass']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass']);
	$sql = "SELECT * FROM users WHERE user='$user' && WHERE pass='$pass'";
	$result = mysql_query($sql);
	$count=mysql_num_rows($result);
	
if($count==1){
		
		echo "Login Complete";	
		
		}
		
		if ($count == 0) {
		
		echo "Username or password are incorrect";

		}	
	
}
?>
</body>
</html>

Thanks, Daniel

#2 logu

logu
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 14 September 2006 - 08:47 AM


hai
  the error is in your qurey

"SELECT * FROM users WHERE user='$user' && WHERE pass='$pass'

there are 2 where's in the query

it should be

"SELECT * FROM users WHERE user='$user' &&  pass='$pass'"


#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 09:01 AM

It should be... "SELECT * FROM users WHERE user='$user' &&  pass='$pass'";


I think it's preferable to use AND when dealing with strings isn't it?... "SELECT * FROM users WHERE user='$user' AND pass='$pass'";

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users