Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bom dia a todos, gostaria que minhas variáveis não vinhece vazias, ja tentei colocar o isset e o empty, mais mesmo assim eles gravam no banco vazia, me ajudem ai
codigo:
<?php
//criar a conexão com o banco
include ("../modulos/config.php");
if(trim(isset($_POST['done']))){
/* echo "<script type='text/javascript'> alert('Todos os campos devem ser preenchidos');</script>";*/
$nome = trim($_POST['nome']);
$usuario = trim($_POST['usuario']);
$senha = trim($_POST['senha']);
$email = trim($_POST['email']);
$sql = mysql_query("INSERT INTO usuario (`nome`, `user`,`senha`, `email`, `data`) VALUES ('$nome', '$usuario', '$senha', '$email', NOW())") or die(mysql_error());
if($sql){
$erro = "Usuário cadastrado com sucesso!";
} else{
$erro = "Não foi possivel cadastrar o usuário";
}
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Painel Administrativo</title>
<!--CSS-->
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<!--***CSS***----->
</head>
<body>
<?php include ("../modulos/topo.php");?>
<div id="conteudo">
<?php include ("../modulos/conteudo.php");?>
<div id="resultado">
<div id="tituloUser"><h3 align="center">Usuários Administradores</h3></div><!--TITULOUSER-->
<?php $select = mysql_query("SELECT * FROM usuario WHERE `status` = 1") or die(mysql_error());
?>
<table id="table">
<tr>
<th id="th">Nome</th>
<th id="th">Login</th>
<th id="th">E-mail</th>
<th id="th">Status</th>
<th id="th">Ações</th>
</tr>
<?php
while($linha = mysql_fetch_assoc($select)){
$id = $linha['id'];
$nome = $linha['nome'];
$login = $linha['user'];
$email = $linha['email'];
$status = $linha['status'];
?>
<tr>
<td id="td"><?php echo $nome ?></td>
<td id="td"><?php echo $login ?></td>
<td id="td"><?php echo $email ?></td>
<td id="td"><?php echo $status ?></td>
<td id="td"><?php echo $nome ?></td>
</tr>
<?php } ?>
</table>
<br />
<br />
<div id="tituloUser"><h3 align="center">Novo Usuário</h3></div><!--TITULOUSER-->
<?php print '<div style="width:80%; background:#ff6600; color:#fff; padding: 5px 0px 5px 0px; text-align:center; margin: 0 auto;">'.$erro.'</div>';
}
?>
<div id="cadUser">
<form action="home.php" method="post" enctype="multipart/form-data"><fieldset id="fieldset">
<legend>Dados</legend>
<table cellspacing="10">
<td>
<label for="nome">Nome: </label>
</td>
<td align="left">
<input name="nome" id="nome" type="text" />
</td>
<tr>
<td>
<label for="usuario">Usuario: </label>
</td>
<td align="left">
<input name="usuario" id="usuario" type="text" />
</td>
</tr>
<tr>
<td>
<label for="senha">Senha:</label>
</td>
<td align="left">
<input name="senha" id="senha" type="password" >
</td>
</tr>
<tr>
<td>
<label for="email">E-mail:</label>
</td>
<td align="left">
<input name="email" id="email" type="email" >
</td>
</tr>
</table>
</fieldset>
<br />
<input type="submit" value="Cadastrar"><input type="hidden" name="done" value="" />
<input type="reset" value="Limpar">
</form>
</div><!--CADUSER-->
</div><!--RESULTADO-->
</div><!--CONTEUDO-->
</body>
</html>Bom analisei alguns erros em seu script tinha uns campos com nomes diferentes como user e usuário, você nomeou o input como user e e invocou o script para o banco como usuário, e outros erros, veja aí se é o que você quer deixe seu script refeito abaixo:
<?php
//criar a conexão com o banco
$acao = strip_tags($_GET['acao'] );
if($acao =='enviar'){
/* echo "<script type='text/javascript'> alert('Todos os campos devem ser preenchidos');</script>";*/
$nome = trim($_POST['nome']);
$usuario = trim($_POST['usuario']);
$senha = trim($_POST['senha']);
$email = trim($_POST['email']);
if(empty($nome)){
echo "<script>alert('Por Favor ! Preencha o nome')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($usuario )){
echo "<script>alert('Por Favor ! Preencha o Campo usuario ')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($senha )){
echo "<script>alert('Preencha o Campo senha !')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($email)){
echo "<script>alert('Preencha o Campo Email!')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "<script>alert('Email Inválido Tente Novamente!')</script>";
echo "<script language='javascript'>history.back()</script>";$data = date( "d/m/Y" );
$hora = date( "H:i:s" );
$cadastrar = mysql_query("INSERT INTO usuario (nome,usuario,senha,email,status) VALUES ('".$nome."', '".$usuario."', '".$senha."', '".$email.",'".$status."')");
if(($cadastrar )==1){
$erro = "Usuário cadastrado com sucesso!";
}else{
$erro = "Não foi possivel cadastrar o usuário";
}
}
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Painel Administrativo</title>
<!--CSS-->
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<!--***CSS***----->
</head>
<body>
<div id="conteudo">
<div id="resultado">
<div id="tituloUser"><h3 align="center">Usuários Administradores</h3></div><!--TITULOUSER-->
<?php $select = mysql_query("SELECT * FROM usuario WHERE status = '1'");
?>
<table id="table">
<tr>
<th id="th">ID</th>
<th id="th">Nome</th>
<th id="th">Login</th>
<th id="th">E-mail</th>
<th id="th">Status</th>
<th id="th">Ações</th>
</tr>
<?php
while($linha = mysql_fetch_array($select)){
$id = $linha['id'];
$nome = $linha['nome'];
$login = $linha['usuario'];
$email = $linha['email'];
$status = $linha['status'];
?>
<tr>
<td id="td"><?php echo $id ?></td>
<td id="td"><?php echo $nome ?></td>
<td id="td"><?php echo $login ?></td>
<td id="td"><?php echo $email ?></td>
<td id="td"><?php echo $status ?></td>
<td id="td"><?php echo $nome ?></td>
</tr>
<?php } ?>
</table>
<br />
<br />
<div id="tituloUser"><h3 align="center">Novo Usuário</h3></div><!--TITULOUSER-->
<?php print '<div style="width:80%; background:#ff6600; color:#fff; padding: 5px 0px 5px 0px; text-align:center; margin: 0 auto;">'.$erro.'</div>';
}
?>
<div id="cadUser">
<form action="http://seu_site.php?acao=enviar" method="post" enctype="multipart/form-data"><fieldset id="fieldset">
<legend>Dados</legend>
<table cellspacing="10">
<td>
<label for="nome">Nome: </label>
</td>
<td align="left">
<input name="nome" id="nome" type="text" />
</td>
<tr>
<td>
<label for="usuario">Usuario: </label>
</td>
<td align="left">
<input name="usuario" id="usuario" type="text" />
</td>
</tr>
<tr>
<td>
<label for="senha">Senha:</label>
</td>
<td align="left">
<input name="senha" id="senha" type="password" >
</td>
</tr>
<tr>
<td>
<label for="email">E-mail:</label>
</td>
<td align="left">
<input name="email" id="email" type="email" >
</td>
</tr>
</table>
</fieldset>
<br />
<input type="hidden" name="done" value="" />
<input type="submit" value="Cadastrar">
<input type="reset" value="Limpar">
</form>
</div><!--CADUSER-->
</div><!--RESULTADO-->
</div><!--CONTEUDO-->
</body>
</html>
OBS: detalhe importante não se usa mais MYSQL esta função esta obsoleta a partir do php 5.5 use MYSQLI ou PDO.
E deixei abaixo o mesmo script , mas convertido para usar a função MYSQLI
<?php
//criar a conexão com o banco
include_once ("config.php");
$acao = strip_tags($_GET['acao'] );
if($acao =='enviar'){
/* echo "<script type='text/javascript'> alert('Todos os campos devem ser preenchidos');</script>";*/
$nome = trim($_POST['nome']);
$usuario = trim($_POST['usuario']);
$senha = trim($_POST['senha']);
$email = trim($_POST['email']);
if(empty($nome)){
echo "<script>alert('Por Favor ! Preencha o nome')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($usuario )){
echo "<script>alert('Por Favor ! Preencha o Campo usuario ')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($senha )){
echo "<script>alert('Preencha o Campo senha !')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(empty($email)){
echo "<script>alert('Preencha o Campo Email!')</script>";
echo "<script language='javascript'>history.back()</script>";
}elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "<script>alert('Email Inválido Tente Novamente!')</script>";
echo "<script language='javascript'>history.back()</script>";$data = date( "d/m/Y" );
$hora = date( "H:i:s" );
$cadastrar = $MySQLi->query("INSERT INTO usuario (nome,usuario,senha,email,status) VALUES ('".$nome."', '".$usuario."', '".$senha."', '".$email.",'".$status."')");
if (mysqli_connect_errno())trigger_error(mysqli_connect_error(), E_USER_ERROR);
if(($cadastrar )==1){
$erro = "Usuário cadastrado com sucesso!";
}else{
$erro = "Não foi possivel cadastrar o usuário";
}
}
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Painel Administrativo</title>
<!--CSS-->
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<!--***CSS***----->
</head>
<body>
<div id="conteudo">
<div id="resultado">
<div id="tituloUser"><h3 align="center">Usuários Administradores</h3></div><!--TITULOUSER-->
<?php $select = $MySQLi->query("SELECT * FROM usuario WHERE status = '1'");
if (mysql_connect_errno())
trigger_error(mysql_connect_error(), E_USER_ERROR);
?>
<table id="table">
<tr>
<th id="th">ID</th>
<th id="th">Nome</th>
<th id="th">Login</th>
<th id="th">E-mail</th>
<th id="th">Status</th>
<th id="th">Ações</th>
</tr>
<?php
while($linha = mysqli_fetch_array($select)){
$id = $linha['id'];
$nome = $linha['nome'];
$login = $linha['usuario'];
$email = $linha['email'];
$status = $linha['status'];
?>
<tr>
<td id="td"><?php echo $id ?></td>
<td id="td"><?php echo $nome ?></td>
<td id="td"><?php echo $login ?></td>
<td id="td"><?php echo $email ?></td>
<td id="td"><?php echo $status ?></td>
<td id="td"><?php echo $nome ?></td>
</tr>
<?php } ?>
</table>
<br />
<br />
<div id="tituloUser"><h3 align="center">Novo Usuário</h3></div><!--TITULOUSER-->
<?php print '<div style="width:80%; background:#ff6600; color:#fff; padding: 5px 0px 5px 0px; text-align:center; margin: 0 auto;">'.$erro.'</div>';
}
?>
<div id="cadUser">
<form action="http://seu_site.php?acao=enviar" method="post" enctype="multipart/form-data"><fieldset id="fieldset">
<legend>Dados</legend>
<table cellspacing="10">
<td>
<label for="nome">Nome: </label>
</td>
<td align="left">
<input name="nome" id="nome" type="text" />
</td>
<tr>
<td>
<label for="usuario">Usuario: </label>
</td>
<td align="left">
<input name="usuario" id="usuario" type="text" />
</td>
</tr>
<tr>
<td>
<label for="senha">Senha:</label>
</td>
<td align="left">
<input name="senha" id="senha" type="password" >
</td>
</tr>
<tr>
<td>
<label for="email">E-mail:</label>
</td>
<td align="left">
<input name="email" id="email" type="email" >
</td>
</tr>
</table>
</fieldset>
<br />
<input type="hidden" name="done" value="" />
<input type="submit" value="Cadastrar">
<input type="reset" value="Limpar">
</form>
</div><!--CADUSER-->
</div><!--RESULTADO-->
</div><!--CONTEUDO-->
</body>
</html>
Espero te ajudado...
Verifica se todas foram setas
$erro= false;
if(!isset($nome, $usuario, $senha, $email)){
outra opção ver quais estão vazias
if( empty( $nome ) ) {
if( empty( $etc ) ) {
Caso achou algum erro, não deixe cadastrar