Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

ecacarva

nao grava

Recommended Posts

Ola PessoalTenho o codigo abaixo que mostra minha tela certinho com botao e tudo, mas quando clico o botão Cadastra cliente,simplesmente nao grava. Percebi que a minha variavel acao esta sempre vazia.Alguem pode dar um helpinclude "conecta.php"; //Conecta com a nosso banco de dados MySQL include "ver_sessao.php"; //Verifica se a sessão está ativa?><html><head> <title>Tutorial iMasters</title></head> <body bgcolor="#FFFFFF" text="#000000"> <br> <table width="60%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td height="60"> <div align="center"><font face="Arial" size="4"><b>Cadastro de Clientes</b></font></div></td> </tr> </table> <br> <? if($acao == 'cadastrar') { /*Cadastra o cliente depois que o formulário for enviado */ //Verifica os dados enviados if($nome_user == '') { $erros++; $html_erros = $html_erros."<br>Nome"; } if($end_user == '') { $erros++; $html_erros = $html_erros."<br>Endereço"; } if($bairro_user == '') { $erros++; $html_erros = $html_erros."<br>Bairro"; } if($email_user == '') { $erros++; $html_erros = $html_erros."<br>Email"; } if($tel_user == '') { $erros++; $html_erros = $html_erros."<br>Telefone"; } if($cidade_user == '') { $erros++; $html_erros = $html_erros."<br>Cidade"; } if($estado_user == 0) { $erros++; $html_erros = $html_erros."<br>Estado"; } if($erros == 0) { echo "<p align=\"center\"><big><strong>VAI GRAVAR</strong></big></p>"; $sql = mysql_query("INSERT INTO tb_clientes(inclusao_user,nome_user,end_user,bairro_user,email_user, tel_user,cidade_user,estado_user) VALUES(now(),'$nome_user','$end_user','$bairro_user', '$email_user','$tel_user','$cidade_user','$estado_user')") or die("Erro no comando SQL:".mysql_error()); echo "<div align=center><font face=Arial size=2>Cliente cadastrado com Sucesso!! <br><br><a href='java script:history.go(-2)'><< Voltar</a></font></div><br><br>"; } //fecha $erros == 0 else { echo "<div align=center><font face=Arial size=2><b>ATENÇÃO</b><br><br>Foram encontrados <b>$erros</b> erro(s) no cadastro do cliente:<br><b>$html_erros</b> <br><br><a href='java script:history.go(-1)'><< Voltar</a></font></div><br><br>"; }//fecha else } /*fecha acao= cadastrar*/ ?> <? if($acao == '') { /*Mostra o formulário de cadastro de clientes */ $sql_estados = mysql_query("SELECT * FROM tb_estados ORDER BY estado") or die("ERRO no comando SQL:".mysql_error()); ?> <form name="frm_clientes" method="post" action="cadclientes.php?acao=cadastrar"> <table width="80%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="24%" height="25"><font face="Arial" size="2">Nome:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <input type="text" name="nome_user" size="35"></font></td> </tr> <tr> <td height="25" width="24%"><font face="Arial" size="2">Endereço:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <input type="text" name="end_user" size="30"></font></td> </tr> <tr> <td height="25" width="24%"><font face="Arial" size="2">Bairro:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <input type="text" name="bairro_user" size="30"></font></td> </tr> <tr> <td height="25" width="24%"><font face="Arial" size="2">Email:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <input type="text" name="email_user" size="35"></font></td> </tr> <tr> <td height="25" width="24%"><font face="Arial" size="2">Telefone:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <input type="text" name="tel_user" size="20"></font></td> </tr> <tr> <td height="25" width="24%"><font face="Arial" size="2">Cidade:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <input type="text" name="cidade_user" size="35"></font></td> </tr> <tr> <td height="25" width="24%"><font face="Arial" size="2">Estado:</font></td> <td height="25" width="76%"><font face="Arial" size="2"> <select name="estado_user"> <option value="0"><< Selecione o estado >></option> <?while($array = mysql_fetch_array($sql_estados)) {?> <option value="<?echo $array['id_estado'];?>"><?echo $array['estado'];?></option> <?}?> </select></font></td> </tr> <tr> <td height="25" colspan="2"> <div align="center"> <input type="submit" name="cadastrar" value="Cadastrar cliente >>"></div></td> </tr> </table> </form> <?} /*fecha acao=entrar */?> </body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

include "conecta.php"; //Conecta com a nosso banco de dados MySQLinclude "ver_sessao.php"; //Verifica se a sessão está ativacaro amigo o certo seriainclude("conecta.php");include("ver_sessao.php");

Compartilhar este post


Link para o post
Compartilhar em outros sites

acho que nao é isso nao... ...pq você nao tenta passar essa acao como um campo hidden???<input type="hidden" name="acao" value="cadastrar">?

Compartilhar este post


Link para o post
Compartilhar em outros sites

O animar'z está correto, passar por hidden tb seria outra solução, mas deveria estar dando certo por submit tb.Antes de usar esta váriável tenta dar um echo nela pra ver o que aparece.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Como eu faria...Eu iria dar um echo em todas as variaveis antes de tentar gravar no bd...assim eu veria se ta tudo certinho... ...se tiver passando direitinho os valores, seu problema é com o bd... :/Ai eu nao sei, pois uso o adobd que é uma abstracao de bd e ai, sintaxe nao sei nada... :(

Compartilhar este post


Link para o post
Compartilhar em outros sites

você ta trabalhando com o register_globals = on deixe ele em off

 

e você precisa pegar essas variaveis exemplo:

 

$nome_user = $_POST["nome_user"];

 

e pra nao ter erro use isset() pra verificar se foi enviado o formulario

 

include "conecta.php"; //Conecta com a nosso banco de dados MySQL

include "ver_sessao.php"; //Verifica se a sessão está ativa

 

 

caro amigo o certo seria

 

include("conecta.php");

include("ver_sessao.php");

 

tanto faz funciona sem os ( ) tbm nao tem problema

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.