Hi, I was wondering why this error occurs in my scipt . php: mysql_num_rows() expects Parameter 1 to be Resource, Boolean Given in

Asked

Viewed 19 times

-3

<?php
    $error = "";
    if(isset($_POST['registrar'])){
        $nome = $_POST['nome'];
        $email = $_POST['email'];
        $apelido = $_POST['apelido'];
        $pass = $_POST['pass'];
        $cpass = $_POST['cpass'];
        $notify = $_POST['notify'];

        $verify = mysql_query("SELECT * FROM users WHERE email = '$email'");

        if(strlen($nome) < 3){
            $error = "<h2 style='color:red'>Nome muito pequeno!</h2>";
        }else if(strlen($email) < 8){
            $error = "<h2 style='color:red'>Email muito pequeno!</h2>";
        }else if(strlen($apelido) < 3){
            $error = "<h2 style='color:red'>Apelido muito pequeno!</h2>";
        }else if(strlen($pass) < 8){
            $error = "<h2 style='color:red'>Senha muito pequena!</h2>";
        }else if($pass != $cpass){
            $error = "<h2 style='color:red'>As duas senhas não batem!</h2>";        
        }else if(mysql_num_rows($verify) > 0){
            $error = "<h2 style='color:red'>Email ja registrado!</h2>";
        }else{
            mysql_query("INSERT INTO users (`nome`,`email`,`apelido`,`senha,`notify,`active`) VALUES ('$nome','$email','$apelido','$pass','$notify','false')");
            $error = "<h2 style='color:green'>Sua conta foi registrada, Entre em seu email para verificar.</h2>";
        }
    }
?>

<!DOCTYPE html>
<html>
<head>
    <title>Register - TheNiceComp</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <?php include("header.php"); ?>
    <center>
        <h1>Registre-se</h1>
        <div class="panel">
            <?php echo $error; ?>
            <form method="POST">
                <table width="50%">
                    <tr>
                        <td style="float: right;">Nome:</td>
                        <td><input type="name" name="nome"></td>                
                    </tr>
                    <tr>
                        <td style="float: right;">Email:</td>
                        <td><input type="email" name="email"></td>              
                    </tr>   
                    <tr>
                        <td style="float: right;">Apelido:</td>
                        <td><input type="name" name="apelido"></td>             
                    </tr>   
                    <tr>
                        <td style="float: right;">Senha:</td>
                        <td><input type="password" name="pass"></td>                
                    </tr>   
                    <tr>
                        <td style="float: right;">Confirme a Senha:</td>
                        <td><input type="password" name="cpass"></td>               
                    </tr>
                    <tr>
                        <td style="float: right;">Receber novidades no Email:</td>
                        <td><input type="checkbox" name="notify"></td>              
                    </tr>
                </table>
                <input type="submit" name="registrar" value="Registrar" style="width: 50%">
            </form>
        </div>
    </center>
</body>
</html>

any help I appreciate!!

  • Hello @Thenicecomp, had the opportunity to check the reply?

  • If the answer answered you, do not forget to vote and accept it.

1 answer

0

There is some error in executing your select, so $verify is false and how it is passed on to mysql_num_rows this error is then presented.

You need to check the success of query with, for example,

if (!$verify) {
    die('Invalid query: ' . mysql_error());
}

Another important detail to mention is that these methods were removed in PHP 7 and should be replaced by mysqli_num_rows and mysqli_query.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.