Error using mysql_num_rows [closed]

0

Could you help me with this little code?

    <?php
    include("../app/database.php");
    if (isset($_POST['registrar'])){
        if (($_POST['nombre']!='') && ($_POST['email']!='') && ($_POST['clave']!='') && ($_POST['rclave']!='')){
            if ($_POST['clave'] != $_POST['rclave']){
                echo "Las contraseñas no coinciden.";
            }else{
                $name = proteger($_POST['nombre']);
                $mail = proteger($_POST['email']);
                $pass = md5(proteger($_POST['nombre']));
                $u_ip = $_SERVER['REMOTE_ADDR'];
                //VERIFICACION DE EXISTENCIA
                $q = mysql_query("SELECT email FROM usuarios WHERE email = '$mail");
                if(mysql_num_rows($q)>0){
                  echo "Dirección de Correo ya en uso.";
                }else{
                    $registrado = mysql_query("INSERT INTO usuarios (nombre,email,clave,ip) VALUES ('$name','$mail','$pass','$u_ip')");
                    echo "registrado con éxito!";
                }
            }
        }
    }

?>

I get the following error:

 Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\page\registro.php on line 14
registrado con éxito!

But I need you to tell me that the email address is already in use ..

    
asked by Jean 20.01.2017 в 14:12
source

2 answers

1

The problem is in the query. There is a missing 'after the $ email variable so when doing the query it gives error and the mysql_query function returns false instead of the required resource and when doing the mysql_num_rows on a Boolean it returns that warning.

Change

$q = mysql_query("SELECT email FROM usuarios WHERE email = '$mail");

for

$q = mysql_query("SELECT email FROM usuarios WHERE email = '$mail'");

Link to the php manual of the mysql_query function where it explains the return values.

    
answered by 20.01.2017 / 14:20
source
0

@Lithorell's answer is correct although there is another problem with your script and you are using the name field instead of the password to save the MD5.

changes

$pass = md5(proteger($_POST['nombre']));

By

$pass = md5(proteger($_POST['clave']));
    
answered by 20.01.2017 в 14:39