Jump to content

Recommended Posts

Hello,

 

I'm quite new to PHP development so it could be that I'm going to ask some stupid questions  ;D

 

So I'm making a login script and I'm running to a small problem

 

I'm getting this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/MAMP/htdocs/my_projects/first_test_project/auth.php on line 15

 

This comes when I perform the login:

 

my php code:

 

<?php

require "header.php";

function controle($username,$password){
	$sql = "SELECT * FROM klant WHERE Username = '$username' AND Password = '$password'";
}

$username = $_POST['username'];
$password = $_POST['password'];
$login = $_POST['login'];

$result = mysql_query($sql);
if($login && $username && $password){
	$num_rows = mysql_num_rows($result);
	if($num_rows == 1){
		$_SESSION['username'] = $username;
		$_SESSION['password'] = $password;
	}
}

if(controle($_SESSION['username'], $_SESSION['password']) == false){

?>

	<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
		<table width="200px">
			<tr>
				<td>Username:</td>
				<td><input type="text" name="username"></td>
			</tr>
			<tr>
				<td>Password:</td>
				<td><input type="password" name="password"></td>
			</tr>
			<tr>
				<td><input type="submit" name="login" value="Login"></td>
			</tr>
		</table>
	</form>

<?php

}

require "footer.php";

?>

 

I'm thinking that I made a mistake somewhere, but don't know where  ???

Link to comment
https://forums.phpfreaks.com/topic/154093-solved-login-script/
Share on other sites

$sql must be used where it is defined. Since it is not a global character and your function does not return it, it is pointless to define like you have, that and you did not call the function anyhow.

 

What do you have it in a function in the first place?

 

PHP Functions Manual I would suggest looking at proper usage of functions.

Link to comment
https://forums.phpfreaks.com/topic/154093-solved-login-script/#findComment-810006
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.