Notice: Undefined variable: name in C: \ wamp

-5
<?php

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

    extract($_POST);

    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: ./');  
           }

        }

       }

    }

    }

  ?>
    
asked by anonymous 16.09.2014 / 05:06

1 answer

4

PHP is responding that the variable has not been defined (Undefined variable). Use isset to verify that the variable was created.

if( isset( $nome ) )
{
    if( $nome == '' OR strlen( $nome ) < 4 )
    {
        echo 'menor que 4';
    }
}

OBS 1. $nome == '' and $nome === '' have a different result depending on the typing of the variable, see operators .

OBS2. strlen does not return the exact string size when it has special characters. Prefer to use mb_strlen to work with strings.

If you want to get a form field, use $_POST['nome_do_campo'] . NEVER use extract in form data. Imagine the scenario below with a user injecting a <input name="pdo" />

<form method="post">
     <input name="pdo" />
</form>

$PDO = new PDO( ... );
extract($_POST);

You will lose your PDO instance.

    
16.09.2014 / 05:32