I am trying to make a select
in the database for testing, this select
displays the user data after entering username and password. The error happens after select
:
Warning: mysql_fetch_array () expects parameter 1 to be resource, integer given in C: \ xampp \ htdocs \ PHP1 \ query.php on line 57
<? php
if (@$_GET['go'] == 'consultar') {
$user = $_POST['usuario'];
$pwd = $_POST['senha'];
if (empty($user)) {
echo "<script>alert('Preencha todos os campos para logar-se.'); history.back();</script>";
}
elseif(empty($pwd)) {
echo "<script>alert('Preencha todos os campos para logar-se.'); </script>";
} else {
$query1 = mysql_num_rows(mysql_query("SELECT * FROM USUARIO WHERE USUARIO = '$user' AND SENHA = '$pwd'"));
if ($query1 == 1) {
echo "<table><tr><td>Login</td><td>Nome do Usuário</td><td>Senha do Usuário</td></tr>";
while ($escrever = mysql_fetch_array($query1)) {
/*Escreve cada linha da tabela*/
echo "<tr><td>".$escrever['usuario'].
"</td><td>".$escrever['nome'].
"</td><td>".$escrever['senha'].
"</td></tr>";
}
echo "</table>";
} else {
echo "<script>alert('Usuário ou senha não correspondem!');</script>";
}
}
} ?>
<?php require_once "config.php"; ?>
<html>
<head>
<meta charset=utf-8>
<meta name=description content="">
<meta name=viewport content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Cadastro com PHP</title>
</head>
<body>
<div id="cadastro">
<form method="post" action="?go=consultar">
<table id="login_table">
<tr>
<td>Usuário:</td>
<td>
<input type="text" name="usuario" id="usuario" class="txt" maxlength="15" />
</td>
</tr>
<tr>
<td>Senha:</td>
<td>
<input type="password" name="senha" id="senha" class="txt" maxlength="15" />
</td>
</tr>
<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 colspan="2">
<input type="submit" value="Consultar" id="btn">
</tr>
</table>
</form>
</div>
</body>
</html>