SQLSTATE [21S01]:插入值列表与列列表不匹配:1136列计数与第1行的值计数不匹配

时间:2016-07-15 21:28:12

标签: php mysql pdo

谁能帮助我吗? 当我尝试注册一个新的管理员时,系统显示错误:SQLSTATE [21S01] 我从类似的问题得到了以下代码,但它没有解决问题

这是我的class.admin.php,包含我注册新管理员的功能

public function registro_admin($auser, $aemail, $apass, $adep, $aname, $alast, $agender, $amatricula){
  try{
    $new_password = password_hash($apass, PASSWORD_BCRYPT);
    $stmt = $this->db->prepare("INSERT INTO Admin(admin_user,
    admin_email,
    admin_password,
    admin_departamento,
    admin_name,
    admin_lastname,
    admin_matricula)
    VALUES(:auser, :aemail, :apass, :adep, :aname, :alast, :agender, :amatricula)");
    $stmt->bindparam(":auser", $auser);
    $stmt->bindparam(":aemail", $aemail);
    $stmt->bindparam(":apass", $apass);
    $stmt->bindparam(":adep", $adep);
    $stmt->bindparam(":aname", $aname);
    $stmt->bindparam(":alast", $alast);
    $stmt->bindparam(":agender", $agender);
    $stmt->bindparam(":amatricula", $amatricula);
    #$stmt->bindparam(":apic", $apic);
    $stmt->execute();

    return $stmt;
  }catch(PDOException $e){
    echo $e->getMessage();
  }
}

这是我的admin-register.php,它包含我的html表单和php代码验证

  else if(strlen($apass) < 6){
  echo '<script>alert("Password must be contain more than 6 characters");</script>';
}else{
  try{
    $stmt = $db_con->prepare("SELECT admin_user, admin_email FROM Admin WHERE admin_user=:auser OR admin_email=:aemail");
    $stmt->execute(array(':auser'=>$auser, ':aemail'=>$aemail));
    $row=$stmt->fetch(PDO::FETCH_ASSOC);

    if($row['admin_user'] == $auser){
      echo '<script>alert("Lo sentimos, el usuario ya existe");</script>';
    }
    else if($row['admin_email'] == $aemail){
      echo '<script>alert("Lo sentimos, el correo ya existe");</script>';
    }else{
      if($admin->registro_admin($auser, $aemail, $apass, $adep, $aname, $alast, $agender, $amatricula)){
        echo '<script>alert("Administrador Agregado con Éxito");</script>';
      }
    }
  }catch(PDOException $e){
    echo $e->getMessage();
  }
}

请帮助:(

1 个答案:

答案 0 :(得分:1)

您的INSERT INTO中只定义了七列。您需要在那里添加性别列。

请在admin_gender

下添加admin_lastname