Form not registered, no name is saved

Asked

Viewed 203 times

-4

My form is not saving any data in the bank, which may be?

<div id="formulario">      <div align="left">
    <?php

      if(isset($_SERVER['REQUEST_METHOD']) AND $_SERVER['REQUEST_METHOD'] == 'POST'){

        extract($_POST);

    if(isset($nome))
        if($nome === '' OR strlen($nome)<4){
            echo 'Insira um nome existente';
        }elseif($sobrenome=='' OR strlen($sobrenome)<6){ 
            echo 'Insira um sobrenome existente';
        }elseif($email==''){
            echo 'Insira seu e-mail';
        }elseif(!preg_match("/^[az0-9_\.\-]+@[az0-9_\.\-}*{a-z0-9_\-]+\.[a-z]{2,4}$/i",$email)){
            echo 'E-mail invalido tente outro';
        }else{

            include('../../sllapsocial/classes/DB.class.php');

            $verificar = DB::getConn()->prepare("SELECT `id` FROM `usuarios` WHERE `email`=?");
            if($verificar->execute(array($email))){
                if($verificar->rowCount()>=1){
             echo 'Este e-mail ja existe';

         }elseif($senha=='' OR strlen($senha)<4){
            echo'Senha fraca Insira mais caracteres';
         }elseif(strtolower($capctha) <> strtolower($_SESSION['capcthaCadastro'])){
             echo 'Codigo errado';
         }else{
             $senhaInsert = sha1($senha);
             $nascimento = "$ano-$mes-$dia";
             $inserir = DB::getConn()->prepare("INSERT INTO `usuarios` SET `email`=?, `senha` =?, `nome`=? `sobrenome`=?, `sexo`=?, `nascimento`=?`cadastro`=NOW()");

             if($inserir->execute(array($nome,$sobrenome,$email,$senhaInsert,$nascimento,$sexo))){
            header('Location: ./');  
               }

            }

           }

        }

        }

      ?>
  </div>
  <h3 align="left">Para ter acesso,É facil e gratis.</h3>
 <form name="cadastro" action="" method="post" >
   <div>
    <div class="inputfloat">
         <div align="left"><span>Nome</span>
         <input name="Nome" type="text" class="txtInput" value="<?php if(!empty($nome)) echo $nome; ?>" size="40"/>
         <div>

          <div class="inputfloat">
             <span>Sobrenome</span>
             <input name="Sobrenome" type="text" class="txtInput" value="<?php if(!empty($sobrenome)) echo $sobrenome; ?>" size="40"/>
             <div>

           <span class="spanHide">Seu e-mail</span>
             <input name="Seu e-mail" type="text" class="txtInput" value=" <?php  if(!empty($email)) echo $email; ?>" size="40"/>

             <span class="spanHide">Insira o e-mail novamente</span>
             <input name="Insira o e-mail novamente" type="text" class="txtInput" size="40" value=" <?php if(!empty($email)) echo $email; ?>" />

             <span class="spanHide">Senha</span>
             <input name="Senha" type="password" class="txtInput" size="40" value="<?php  if(!empty($senha)) echo $senha; ?>" />

           <span class="spanHide">Data de nascimento</span>
             <select name="Dia">
               <option value="">Dia</option>
               <?php 
         for($d=1;$d<=31;$d++){
             $zero = ($d<10) ? 0 : '';
             if(!empty($dia)==$zero.$d){
             echo '<option selected="selected" value="',$zero,$d,'">',$zero,$d,'</option>';
             }else{
             echo '<option value="',$zero,$d,'">',$zero,$d,'</option>';
             }

         }

      ?>

             </select>

             <select name="Mes">
               <option value="">M&ecirc;s</option>
               <?php
       $meses = array('','janeiro','fevereiro','março','abril','maio','junho','julho','agosto','setembro','outubro','novembro','dezembro');
       for($m=1;$m<=12;$m++){
       $zero = ($m<10) ? 0 : '';
       if($zero.$m == $meses){
        echo '<option selected="selected"value="',$zero,$m,'">',$meses[$m],'</option>';
       }else{
            echo '<option "value="',$zero,$m,'">',$meses[$m],'</option>';
       }
       }
      ?>

             </select>

             <select name="Ano">
               <option value="">Ano</option>
               <?php
      for($a=date('Y');$a>=(date('Y')-100);$a--){
          if(!empty($ano)){
              echo '<option selected"selected" value="',$a,'">',$a,'</option>';
          }else{
              echo '<option value="',$a,'">',$a,'</option>';      
        }
      }
      ?>

             </select>

             <span class="spanHide">Sou do sexo</span>
             <select name="sexo">
               <option <?php if(!empty($sexo) == 'masculino') echo'selected"selected"'; ?> value="masculino" >Masculino</option> 
               <option <?php if(!empty($sexo) == 'feminino') echo'selected"selected"'; ?>value="feminino" >Feminino</option> 
             </select>         
    </div>
    <div class="captchafloat">
             <div align="left"><img src="../site/captcha.php" /></div>
    </div>

         <div class="inputFloat">
           <div align="left"><span>Digite o código acima:</span>
             <input class="txtInput" type="text" name="captcha"  />
             <input type="submit" value="Continue" class="SubmitContinue" name="Continue" />
        </form>
    </div><!--formulario-->
  • Hello David, welcome to [en.so]. Please take more care in formatting the questions (you can always [Edit] to improve). Also, try to include more information to help others respond. Is there an error message? Have you tried any debug? Do you have any leads? etc. The more you say, the more chance you have of getting an answer. Thank you.

  • yes I tried to debug more did not get any results as if this code does not exist in the form

  • 2

    Start by lowering all the fields of the Forms, as you are mixing everything when using the variables. Another thing, as already recommended on other occasions, disappear with this extract of your code and use direct declaration $nome = $_POST['nome']; etc. I think this is a good start to moving forward in the code.

  • Unfortunately Bacco did not work this method is appearing Notice: Undefined index: name in C: wamp www redesocial styles index.php on line 68

  • This is a good sign. A warning that was no 'name' field in the form.

  • Bacco I changed everything else Still the same mistake

  • is continuation this one?

  • yes but this is another account I lost the password

  • 1

    Beware of the attribute name input’s, they are not to put message, are the name of the parameters sent in the POST.

  • If you give an Insert with defined data ($inserir->execute(array('nome' , 'sobrenome' ...) ) ) they are recorded in DB or not?

  • 1

    not PAPA charlie I put the name and surname in capital letters and it worked :) now the problem is oemail Notice: Undefined variable: Email in

  • Follow @Lost’s reply, and if the question has been resolved, check the answer.

  • PESSOAL RESOLVI ESSE LADO agora esta dando o seguinte erro Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1049] Base 'redeocial' inconnue' in C:\wamp\www\redesocial\classes\DB.class.php on line 6&#xA;( ! )&#xA;PDOException: SQLSTATE[HY000] [1049] Base 'redesocial' inconnue in C: wamp www redesocial classes DB.class.php on line 6 Call Stack # Time Memory Function Location 1 0.0029 157776 {main}( ) .. index.php:0 2 0.0049 163328 DB::getConn( ) .. index.php:82 3 0.0049 163752 __Construct ( ) .. DB.class.php:6

  • Either the database name is wrong or it does not exist, direct test the database command: show databases. Anything create a new question describing the problem and what I already try to do to solve it.

  • @lost database is working right, I’m following Bacco’s previous advice I took the Extract() and added $name = $_POST['name'];

Show 10 more comments

1 answer

2

1 - Be careful typing field/variable names in html/php Nome is different from nome, see in your form how this definition:

<input name="Nome" type="text"

In php after php Extract() he’ll turn $Nome and not $nome.

if(isset($nome))

2-sql

Appears to be syntax error in Insert:

INSERT INTO `usuarios` SET
 `email`=?,
 `senha` =?,
 `nome`=? <---- falta uma virgula
 `sobrenome`=?,
 `sexo`=?,
 `nascimento`=? <---- aqui também
 `cadastro`=NOW()

Whenever mysql returns the code 1064 always is some syntax error like column/table name misspelled or quotation marks in wrong places.

The mesnagem of error is similar to:

Error Code: 1064. You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '' at line 1

List of mysql error codes

Syntax to the Insert alternative

Browser other questions tagged

You are not signed in. Login or sign up in order to post.