Jump to content


Photo

Verificar E Gravar Em Duas Tabelas


  • Faça o login para participar
2 replies to this topic

#1 SR. JSC

SR. JSC

    Turista

  • Usuários
  • 25 posts
  • Sexo:Masculino
  • Localidade:Rio de Janeiro

Posted 27/11/2009, 16:42

Pessoal o último tópico me ajudaram a gravar em duas tabelas do Mysql Porém preciso agora verificar se o usuário realmente preencheu o campo antes de gravar. Após várias dicas de amigos me embolei com umas e outras, porém tentei fazer diferente mas com todas as dicas juntas:

veja como estou tentando:

<?phpsession_start();if(isset($_POST['gravar']))header("Location: ok.php");include("configuracao/conexao.php");if($_SESSION["admin"]==""){$login = "login";$senha = "senha";$email = "email";$nome =  "nome";if(isset($_POST['gravar'])){// Somente números no campo IDif (!is_numeric($_POST['$login'])){$erro++;$mensagem = "<div class=\"erro\">O Campo \"ID\" deve conter apenas números!</div>";}// Validando o campo senhaif(empty($_POST['$senha'])){$erro++;$erro_senha = "<span class=\"erro\">O campo senha não pode ficar em branco.</span>\r";}// Validando o campo nomeif(empty($_POST['$nome'])){$erro++;$erro_nome = "<span class=\"erro\">O Campo \"Nome\" não pode ficar em branco!.</span>\r";}// Validando o campo e-mailif(empty($_POST['$email'])){$erro++;$erro_email = "<span class=\"erro\">O Campo \"email\" não pode ficar em branco!</span>\r";}if ($erro == 0) {        $sql = "INSERT INTO table_cliente (id, login, senha) VALUES ('','$login','$senha')";        $sql2 = "INSERT INTO newsletter_emails (id, email, nome, data_reg, categoria, status, md5) VALUES ('','$email','$nome','2008-07-21 19:27:26','Amigos','yes','')";                mysql_query($sql);        mysql_query($sql2);}}}?><meta http-equiv="Content-Language" content="pt-br"><form action="nova.php" method="post">  <div align="center">    <center>        <IMG src="images/painel.jpg" width=900 height=120 >        <br><b><strong>&Aacute;rea de Ferrmentas</b></strong><br>        Cadastrando um novo ID para acesso<br>    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100" height="106">      <tr>        <td width="100%" height="4"><b><font face="Arial" size="1">Seu ID:</font></b></td>      </tr>      <tr>        <td width="100%" height="15"><font face="Arial">        <input name="login" size="45" style="font-family: Arial; font-size: 8 pt; color: #000000; font-weight: bold; border: 3px double #EBEBEB; padding: -4"></font><?php echo $mensagem; ?></td>      </tr>      <tr>        <td width="100%" height="12"><b><font face="Arial" size="1">Senha:</font></b></td>      </tr>      <tr>        <td width="100%" height="20"><font face="Arial">        <input name="senha" size="45" style="font-family: Arial; font-size: 8 pt; color: #FF0000; font-weight: bold; border: 3px double #EBEBEB; padding: -4" type="password"></font><?php echo $erro_senha; ?></td>      </tr>      <tr>        <td width="100%" height="19"><hr color="#FF0000" size="1"></td>      </tr>          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100" height="106">      <tr>        <td width="100%" height="4"><b><font face="Arial" size="1">Seu E-mail:</font></b><?php echo $erro_email; ?></td>      </tr>      <tr>        <td width="100%" height="15"><font face="Arial">        <input name="email" size="45" style="font-family: Arial; font-size: 8 pt; color: #000000; font-weight: bold; border: 3px double #EBEBEB; padding: -4"></font></td>      </tr>            <tr>        <td width="100%" height="19"><hr color="#FF0000" size="1"></td>      </tr>          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100" height="106">      <tr>        <td width="100%" height="4"><b><font face="Arial" size="1">Seu Nome:</font></b></td>      </tr>      <tr>        <td width="100%" height="15"><font face="Arial">        <input name="nome" size="45" style="font-family: Arial; font-size: 8 pt; color: #000000; font-weight: bold; border: 3px double #EBEBEB; padding: -4"></font><?php echo $erro_nome; ?></td>      </tr>      <tr>      <tr>        <td width="100%" height="24">        <p align="center">        <input type="submit" name="gravar" class="button" value="Cadastrar usuário" style="font-family: ARIAL; font-size: 8 pt; font-weight: bold; border: 3px double #FF0000; padding: -4; background-color: #FFFFFF"></td>      </tr>    </table>    </center>  </div></form><?}}include "infor.php";?>

mas o erro informado é este:

Parse error: syntax error, unexpected $end in /home/grupoinv/public_html/ferr/painel/nova.php on line 105


Não é possível fazer assim?

Edição feita por: Maykel Esser, 27/11/2009, 16:58.
Remoção de estilos e inserção de codebox


#2 Maykel Esser

Maykel Esser

    Super Veterano

  • Usuários
  • 1536 posts
  • Sexo:Masculino
  • Localidade:Curitiba - PR

Posted 27/11/2009, 17:00

Olá amigo! Editei seu post pois estava contra as regras.
Evite postar códigos duplicados. Apenas edite o seu antigo e está tudo certo.

Na sua linha 4, você não está iniciando o if

está assim hoje:
[codebox]if(isset($_POST['gravar']))[/codebox]

tente assim:
[codebox]if(isset($_POST['gravar'])){[/codebox]

Se este post lhe ajudou, ajude o fórum também. Use a reputação de mensagens! add.png


#3 SR. JSC

SR. JSC

    Turista

  • Usuários
  • 25 posts
  • Sexo:Masculino
  • Localidade:Rio de Janeiro

Posted 28/11/2009, 14:35

Pessoal graças ao Forum wmonline e seus colaboradores economizei um bom dinheiro, não sou programador mas a curiosidade junto com a nescessidade faz de você o que quiser ser nem que seja para resolver um problema.

O Felipe Grabriel me ensinou como gravar em duas tabelas neste tópico:

http://forum.wmonlin..._1

e o Without a Nick me ensinou a verificar os campos neste tópico:

http://forum.wmonlin...__fromsearch__1

ENTÃO FICOU BEM SIMPLES ASSIM:


PÁGINA 1- com o formulário e as verificações em java: (nome: nova.php)

<?php
session_start();
include("configuracao/conexao.php");

?>
<script language="javascript">
<!--
function valida() {
var login=document.nova.login.value;
var senha=document.nova.senha.value;
var email=document.nova.email.value;
var nome=document.nova.nome.value;
if (login=="") {
window.alert("Você tem que digitar o seu ID para Acesso.");
document.nova.login.focus();
return false;
}
if (senha=="") {
window.alert("Por Favor digite sua senha para acesso.");
document.nova.senha.focus();
return false;
}
if (email=="") {
window.alert("Por Favor Digite seu email.");
document.nova.email.focus();
return false;
}
if (email.indexOf("@") == -1 || email.indexOf(".") == -1) {
window.alert("E-mail inválido.");
document.nova.email.focus();
return false;
}
if (nome=="") {
window.alert("Digite seu nome ou como deseja ser chamado.");
document.nova.nome.focus();
return false;
}
return true;
document.nova.submit();
}
//-->
</script>
<meta http-equiv="Content-Language" content="pt-br">
<form method="POST" action="gravar.php" name="nova" onsubmit="return valida()">
  <div align="center">
    <center>
        <IMG src="images/painel.jpg" width=900 height=120 >
        <br><b><strong>&Aacute;rea de Ferrmentas</b></strong><br>
        Cadastrando um novo ID para acesso<br>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100" height="106">
      <tr>
        <td width="100%" height="4"><b><font face="Arial" size="1">Seu ID:</font></b></td>
      </tr>
      <tr>
        <td width="100%" height="15"><font face="Arial">
        <input name="login" size="45" style="font-family: Arial; font-size: 8 pt; color: #000000; font-weight: bold; border: 3px double #EBEBEB; padding: -4"></font><?php echo $mensagem; ?></td>
      </tr>
      <tr>
        <td width="100%" height="12"><b><font face="Arial" size="1">Senha:</font></b></td>
      </tr>
      <tr>
        <td width="100%" height="20"><font face="Arial">
        <input name="senha" size="45" style="font-family: Arial; font-size: 8 pt; color: #FF0000; font-weight: bold; border: 3px double #EBEBEB; padding: -4" type="password"></font><?php echo $erro_senha; ?></td>
      </tr>
      <tr>
        <td width="100%" height="19"><hr color="#FF0000" size="1"></td>
      </tr>
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100" height="106">
      <tr>
        <td width="100%" height="4"><b><font face="Arial" size="1">Seu E-mail:</font></b><?php echo $erro_email; ?></td>
      </tr>
      <tr>
        <td width="100%" height="15"><font face="Arial">
        <input name="email" size="45" style="font-family: Arial; font-size: 8 pt; color: #000000; font-weight: bold; border: 3px double #EBEBEB; padding: -4"></font></td>
      </tr>
            <tr>
        <td width="100%" height="19"><hr color="#FF0000" size="1"></td>
      </tr>
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100" height="106">
      <tr>
        <td width="100%" height="4"><b><font face="Arial" size="1">Seu Nome:</font></b></td>
      </tr>
      <tr>
        <td width="100%" height="15"><font face="Arial">
        <input name="nome" size="45" style="font-family: Arial; font-size: 8 pt; color: #000000; font-weight: bold; border: 3px double #EBEBEB; padding: -4"></font><?php echo $erro_nome; ?></td>
      </tr>
      <tr>
      <tr>
        <td width="100%" height="24">
        <p align="center">
        <input type="submit" name="nova" class="button" value="Cadastrar usuário" style="font-family: ARIAL; font-size: 8 pt; font-weight: bold; border: 3px double #FF0000; padding: -4; background-color: #FFFFFF"></td>
      </tr>
    </table>
    </center>
  </div>
</form>
<? include "infor.php";?>

PÁGINA-2 COM A GRAVAÇÃO NO BANCO DE DADOS(nome: gravar.php)
<?php
session_start();
include("configuracao/conexao.php");
if($_SESSION["admin"]==""){

$login = $_POST["login"];
$senha = $_POST["senha"];
$email = $_POST["email"];
$nome = $_POST["nome"];
$sql = "INSERT INTO table_cliente (id, login, senha) VALUES
('','$login','$senha')";

$sql2 = "INSERT INTO newsletter_emails (id, email, nome, data_reg, categoria, status, md5) VALUES
('','$email','$nome','2008-07-21 19:27:26','Amigos','yes','')";

mysql_query($sql);
mysql_query($sql2);
echo "<script>location.href='ok.php'</script>";
}
else
{
echo "<script>location.href='login.htm'</script>";
}
?>

PESSOAL MUITO OBRIGADO POR TUDO!! CONHECI O FORUM NA SEXTA- FEIRA DIA 27/11/2009 E ATÉ AGORA DIA 28/11/2009 RESOLVI TUDO ISSO É MUITO IMPORTANTE.
AGRADEÇO E ESPERO TER AJUDADO A MAIS ALGUÉM TAMBÉM!!

saudações!!
Deus abençoe a todos!!



Edição feita por: SR. JSC, 28/11/2009, 14:42.





1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq