Jump to content

mysql_num_rows error


pedromsouza

Recommended Posts

hi!

 

I need a query that checks if typed login is new or already in use... when I run it...

[27-Jan-2011 20:13:59] PHP Warning:  mysql_num_rows() expects parameter 1 to be resource, null given in /Applications/MAMP/htdocs/recebe_dados_cadastro_usuario.php on line 30

 

Please help me (newbie)!

 

<?php

include "include_conecta_bd.inc";

$nome = $_POST["nome"];

$cpf = $_POST["cpf"];

$cnpj = $_POST["cnpj"];

$login = $_POST["login"];

$email = $_POST["email"];

$ddd = $_POST["ddd"];

$tel = $_POST["tel"];

$sexo = $_POST["sexo"];

$senha1 = $_POST["senha1"];

$senha2 = $_POST["senha2"];

$erro=0;

if(empty($nome))

{echo "Favor digitar um nome.<br>"; $erro=1;}

elseif(strlen($nome)<15)

{echo "Favor digitar nome completo.<br>"; $erro=1;}

elseif(empty($login) or strlen($login)<5)

{echo "O login precisa ter 5 caracteres no mínimo.<br>"; $erro=1;}

elseif((($senha1)!==($senha2)) or (strlen($senha2)<2))

{echo "As senhas não são idênticas.<br>"; $erro=1;}

else

{echo "Dados digitados corretamente!<br>";}

{echo "<p>NOME:$nome<br>CPF:$cpf<br>LOGIN:$login<br>EMAIL:$email<br>TEL:$ddd.$tel<br>SEXO:$sexo<br></p>";}

 

$verif = mysql_query ("select * from usr where login = $login");

$chk = mysql_num_rows ($verif);

if($chk != 0)

{break; echo "Este LOGIN já está em uso!<br>"; }

elseif($verif == 0)

{$resultado = mysql_query ("insert into usr (nome,cpf,login,sexo,email,ddd,tel,senha)

values ('$nome','$cpf','$login','$sexo','$email','$ddd','$tel','$senha1')") or

die(mysql_error());

echo mysql_error();

$linhas = mysql_affected_rows ();

mysql_close ($conexao);

echo "$linhas linha(s) afetada(s)!";}

?>

Link to comment
Share on other sites

Your query is failing.  You need to find out why.  Try echo'ing the query, or just echo mysql_error on failure.

$sql = "select * from usr where login = $login";
$verif = mysql_query ($sql) or die(mysql_error() . ' <br /> in ' . $sql);
$chk = mysql_num_rows ($verif);

 

Link to comment
Share on other sites

I believe it is due to the variable $login NOT being encased by single quotes

 

yep

$verif = mysql_query ("select * from usr where login = $login")

 

shall be

$verif = mysql_query ("select * from usr where login = '$login'")

Link to comment
Share on other sites

That's it! I put quotes and mysql_error()... now it (query) seems to be working but a new error shows up...

 

[27-Jan-2011 20:44:38] PHP Fatal error:  Cannot break/continue 1 level in /Applications/MAMP/htdocs/recebe_dados_cadastro_usuario.php on line 33

 

I wanted it to do the following:

1. if $login is already in use, BREAK to avoid duplicate line...

2. if $login is new, insert into....

 

Thanks a lot for replying!

Link to comment
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.