-2

I'm making an user register system with PHP and MySQL. The problem is when I try to verify if the user is already registered I get the following error:

mysql_num_rows() expects parameter 1 to be resource, boolean given

This is my code:

$sql = mysql_query("SELECT identificacion FROM cliente WHERE identificacion='".$usuario_dni."'");
if(mysql_num_rows($sql) > 0) {
                  echo "Esta identificacion ya ha sido utilizada en un registro anteriormente. <a href='javascript:history.back();'>Reintentar</a>";
              }else {
                  //$usuario_clave = md5($usuario_clave); // Encriptamos la contraseña

                  $reg = mysql_query("INSERT INTO cliente VALUES ('".$usuario_nombre."', '".$usuario_apellidos."', '".$usuario_dni."', '".$usuario_fecha."', '"
                    .$usuario_tlfn."', '".$usuario_pais."' ,".$usuario_email."', NOW())");
                  if($reg) {
                      echo "Usuario Registrado con exito.";
                  }else {
                      echo "Ha ocurrido un error y no se ha podido registrar.";
                  }
Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
David Marí
  • 17
  • 1
  • 3

1 Answers1

0

Probably the mysql_query is returning false as boolean value. Make sure you check the value of $sql. Also please notice that mysql_query has been deprecated. Please check following link:

http://php.net/manual/en/function.mysql-query.php

Francesco Meli
  • 2,183
  • 1
  • 17
  • 40
  • *"Also please notice that mysql_query has been deprecated. Please check following link: http://php.net/manual/en/function.mysql-query.php"* - That's so ironic. – Funk Forty Niner May 25 '17 at 22:24