YellowCrazy 0 Posted April 16, 2016 gente preciso de ajuda, estou criando um sistema de login e eu estou tento o seguinte erro : Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given . e eu não sei como resolver,não quero simplesmente ocultar esses pequenos erros e sim corrigir. coloquei ai em baixo o que eu escrevi e o que está de vermelho e a linha que aparece o erro.. me ajudem <?php require_once "config.php" ?><html> <head> <meta http-equiv="Content-Type" content="text/html, charset=utf-8"> <title>CADASTRO</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="cadastro"> <form method="post" action="?go=cadastrar"> <table id="cad_table"> <tr> <td>Nome:</td> <td><input type="text" name="nome" id="nome" class="txt" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" class="txt" /></td> </tr> <tr> <td>Usuário:</td> <td><input type="text" name="usuario" id="usuario" class="txt" maxlenght="15" /></td> </tr> <tr> <td>Senha:</td> <td><input type="password" name="senha" id="senha" class="txt" maxlenght="15" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="Cadastrar" id="btnCad"></td> </tr> </table> </form> </div> </body> </html> <?php if (@$_GET['go'] == 'cadastrar'){ $nome = $_POST['nome']; $email = $_POST['email']; $user = $_POST['usuário']; $password = $_POST['senha']; if (empty($nome)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($email)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($usuario)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($senha)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }else{ $query1 = mysql_num_rows(mysql_query("SELECT * FROM USUARIO WHERE USUARIO = '$user'")); if($query1 == 1){ echo "<script>alert('Usuário já existe.'); history.back();</script>"; }else{ mysql_query("insert into usuario (nome, email, usuario, senha) values ('$nome', '$email', '$user', '$pwd')"); echo "<script>alert('Usuário cadastrado com sucesso.');</script>"; } } } ?> Share this post Link to post Share on other sites
Annie 1,207 Posted April 16, 2016 Tens que verificar os cenários onde retorna false (erro da query). // Caso a query dê erro, retorna false if (!$query1) { var_dump(mysql_error()); // Dump do erro } elseif ($query1 == 1) { ... // Inserir código aqui } else { ... // O resto do código } Share this post Link to post Share on other sites
YellowCrazy 0 Posted April 16, 2016 Tens que verificar os cenários onde retorna false (erro da query). // Caso a query dê erro, retorna false if (!$query1) { var_dump(mysql_error()); // Dump do erro } elseif ($query1 == 1) { ... // Inserir código aqui } else { ... // O resto do código } não entendi muito bem o que tenho que alterar, pode me explicar de novo? Share this post Link to post Share on other sites
Cσяvσ⋆ 1,804 Posted April 16, 2016 não entendi muito bem o que tenho que alterar, pode me explicar de novo? <?php require_once "config.php" ?><html> <head> <meta http-equiv="Content-Type" content="text/html, charset=utf-8"> <title>CADASTRO</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="cadastro"> <form method="post" action="?go=cadastrar"> <table id="cad_table"> <tr> <td>Nome:</td> <td><input type="text" name="nome" id="nome" class="txt" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" class="txt" /></td> </tr> <tr> <td>Usuário:</td> <td><input type="text" name="usuario" id="usuario" class="txt" maxlenght="15" /></td> </tr> <tr> <td>Senha:</td> <td><input type="password" name="senha" id="senha" class="txt" maxlenght="15" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="Cadastrar" id="btnCad"></td> </tr> </table> </form> </div> </body> </html> <?php if (@$_GET['go'] == 'cadastrar'){ $nome = $_POST['nome']; $email = $_POST['email']; $user = $_POST['usuário']; $password = $_POST['senha']; if (empty($nome)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($email)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($usuario)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($senha)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }else{ $query1 = mysql_num_rows(mysql_query("SELECT * FROM USUARIO WHERE USUARIO = '$user'")); if (!$query1) { var_dump(mysql_error()); } elseif ($query1 == 1) { echo "<script>alert('Usuário já existe.'); history.back();</script>"; } else { mysql_query("insert into usuario (nome, email, usuario, senha) values ('$nome', '$email', '$user', '$pwd')"); echo "<script>alert('Usuário cadastrado com sucesso.');</script>"; } } } ?> Share this post Link to post Share on other sites
YellowCrazy 0 Posted April 16, 2016 <?php require_once "config.php" ?><html> <head> <meta http-equiv="Content-Type" content="text/html, charset=utf-8"> <title>CADASTRO</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div id="cadastro"> <form method="post" action="?go=cadastrar"> <table id="cad_table"> <tr> <td>Nome:</td> <td><input type="text" name="nome" id="nome" class="txt" /></td> </tr> <tr> <td>Email:</td> <td><input type="text" name="email" id="email" class="txt" /></td> </tr> <tr> <td>Usuário:</td> <td><input type="text" name="usuario" id="usuario" class="txt" maxlenght="15" /></td> </tr> <tr> <td>Senha:</td> <td><input type="password" name="senha" id="senha" class="txt" maxlenght="15" /></td> </tr> <tr> <td colspan="2"><input type="submit" value="Cadastrar" id="btnCad"></td> </tr> </table> </form> </div> </body> </html> <?php if (@$_GET['go'] == 'cadastrar'){ $nome = $_POST['nome']; $email = $_POST['email']; $user = $_POST['usuário']; $password = $_POST['senha']; if (empty($nome)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($email)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($usuario)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }elseif (empty($senha)){ echo "<script>alert('Preencha todos os campos para se cadastrar.'); history.back();</script>"; }else{ $query1 = mysql_num_rows(mysql_query("SELECT * FROM USUARIO WHERE USUARIO = '$user'")); if (!$query1) { var_dump(mysql_error()); } elseif ($query1 == 1) { echo "<script>alert('Usuário já existe.'); history.back();</script>"; } else { mysql_query("insert into usuario (nome, email, usuario, senha) values ('$nome', '$email', '$user', '$pwd')"); echo "<script>alert('Usuário cadastrado com sucesso.');</script>"; } } } ?> Agora me da o seguinte erro Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/andreneder/www/daniel/cadastro.php on line 56 string(37) "Nenhum banco de dados foi selecionado" Share this post Link to post Share on other sites
WildEgo 1,486 Posted April 16, 2016 Agora me da o seguinte erro Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/andreneder/www/daniel/cadastro.php on line 56 string(37) "Nenhum banco de dados foi selecionado" Isto é de caras por favor... http://php.net/manual/en/function.mysql-select-db.php Tambem te aconselhava a usar PDO em vez de MySQL.. Share this post Link to post Share on other sites
YellowCrazy 0 Posted April 20, 2016 Isto é de caras por favor... http://php.net/manual/en/function.mysql-select-db.php Tambem te aconselhava a usar PDO em vez de MySQL.. não consigo arrumar cara, pode me ensinar? Share this post Link to post Share on other sites