2017-08-30 68 views
-1

我收到SQLSTATE [HY093]的錯誤:無效參數編號:綁定變量數量與令牌數量不匹配'SQLSTATE [HY093]:無效參數編號:綁定變量數量與令牌數量不匹配'

if (isset($_POST['cadastrar'])){ 
     $nome  = trim(strip_tags($_POST['nome'])); 
     $usuario = trim(strip_tags($_POST['usuario'])); 
     $email = trim(strip_tags($_POST['email'])); 
     $senha = trim(strip_tags($_POST['senha'])); 
     $cpf  = trim(strip_tags($_POST['cpf'])); 
     $rg  = trim(strip_tags($_POST['rg'])); 

     $select = "INSERT INTO registro (nome, usuario, email, senha, cpf, rg) 
            VALUES (:nome, :usuario, email, :senha, :cpf, :rg)"; 

     try{ 
      $result = $conexao->prepare($select); 
      $result->bindParam(':nome', $nome, PDO::PARAM_STR); 
      $result->bindParam(':usuario', $nome, PDO::PARAM_STR); 
      $result->bindParam(':senha', $nome, PDO::PARAM_STR); 
      $result->bindParam(':email', $nome, PDO::PARAM_STR); 
      $result->bindParam(':cpf', $nome, PDO::PARAM_STR); 
      $result->bindParam(':rg', $nome, PDO::PARAM_STR); 
      $result->execute(); 
      $contar = $result->rowCount(); 

      if($contar>0){ 
       echo 'logado com sucesso'; 
      }else{ 
       echo "Os dados digitados estão incorretos"; 
      } 

     }catch(PDOException $e){ 
      echo $e; 
     } 
    } 
+4

查詢中缺少':'。 – tkausl

+2

您在查詢中缺少'email'參數的':'。 – rickdenhaan

回答

1

您的查詢

$select = "INSERT INTO registro (nome, usuario, email, senha, cpf, rg) 
            VALUES (:nome, :usuario, email, :senha, :cpf, :rg)"; 

後變化缺少:在電子郵件

$select = "INSERT INTO registro (nome, usuario, email, senha, cpf, rg) 
             VALUES (:nome, :usuario, :email, :senha, :cpf, :rg)"; 
相關問題