Jump to content
Fórum Script Brasil
  • 0

sistema de login ajuda


ducleboton
 Share

Question

Boa tarde pessoal, não sei quase nada de php e recentemente tentei seguir um tutorial que ensina a criar um sistema de contas para o site, eu precisava colocar um sistema de login e tava no meio do tutorial quando deixou de funcionar como o do video e me perdi.

Criei a database com as informações que eu queria, mas quando vou verificar se a senha e usuário estão corretos da esse erro:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/thunalvr/public_html/area51.php on line 46
Username not found.

esse é o meu codigo:

<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Area 51</title>
</head>

<body>

	<?php
		
	$form ="<form action='./area51.php' method='post'>
    	<table>
        	<tr>
            	<td>Username:</td>
                <td><input type='text' name='user' /></td>
            </tr>
            <tr>
            	<td>Password:</td>
                <td><input type='password' name='password' /></td>
            </tr>
             <tr>
            	<td></td>
                <td><input type='submit' name='loginbtn' value='login' /></td>
            </tr>
        </table>
    </form>";
	
	if ($_POST['loginbtn']){
		$user = $_POST['user'];
		$password = $_POST['password'];
		
		if ($user){
			if ($password){
				require("connect.php");
				
				$password = md5($password);
				//make sure info correct
				
				$query = mysql_query("SELECT * FROM users WHERE username = '$user'");
				$numrows = mysql_num_rows($query);
				if ($numrows == 1){
					$row = mysql_fetch_assoc($query);
					$dbid = $row ['id'];
					$dbuser = $row ['username'];
					$dbpass = $row ['password'];
					$dbactive = $row ['active'];
					
					if ($password == $dbpass) {
						if($dbactive == 1) {
								//set session info
								$_SESSION ['id'] = $dbid;
								$_SESSION ['username'] = $dbuser;
								
								echo "You are logged in as <b>$dbuser</b>. <a href='loggedintest.html'>Click here</a> to go to the member page";
							
							}						
							else
								echo "You must active your account before login. $form";
						}
						else
							echo "The password is incorrect. $form";
						
				}
				
				else
					echo "Username not found.$form";
					
				mysql_close();
				}
				else{
					echo "You must enter a password. $form";
					}
			}
		else 
			echo "You must enter a username. $form";
			
		
		}
	else
		echo $form;
		
	?>
    
    
</body>
</html>

e para ligar ao server tenho esse:

<?php
	
	mysql_connect("localhost", "xxxxxxx", "xxxxxxxx");
	mysql_select_db("thunalvr_test");
	
?>
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Esse aviso geralmente significa que a consulta falhou, pelo que estás a passar um valor booleano (false) para a função mysql_num_rows em vez de um result set.

Tenta, se possível, executar a consulta directamente no MySQL (através do phpMyAdmin ou similar) e verifica se é devolvida alguma coisa.

Link to comment
Share on other sites

Join the conversation

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

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  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.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...