0
I am making a form to save data in the database and this error Erro SQLSTATE [HY093]
<?PHP
$nome = $_REQUEST['Nome'];
$cpf = $_REQUEST['CPF'];
$sexo = $_REQUEST['Sexo'];
$datanasc = $_REQUEST['DataNasc'];
$telefone = $_REQUEST['Telefone'];
$cidade = $_REQUEST['Cidade'];
$bairro = $_REQUEST['Bairro'];
$nomedarua = $_REQUEST['NomedaRua'];
$numerocasa = $_REQUEST['NumeroCasa'];
$complemento = $_REQUEST['Complemento'];
$email = $_REQUEST['Email'];
$senha = $_REQUEST['Senha'];
if(isset($_REQUEST['btnincluir']))
{
try{
$pdo = new PDO('mysql:host=localhost;dbname=consultorio','root','');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('INSERT INTO cliente VALUES(:idcliente,:Nome,:CPF,:Sexo,:DataNasc,:Telefone,:Cidade,:Bairro,:NomedaRua,:NumeroCasa,:Complemento,:Email,:Senha)');
$stmt->execute(array(':Nome' =>$nome,':CPF' =>$cpf,':Sexo' =>$sexo,':DataNasc' =>$datanasc,':Telefone' =>$telefone,':Cidade' =>$cidade,':Bairro' =>$bairro,':NomedaRua' =>$nomedarua,':NumeroCasa' =>$numerocasa,':Complemento' =>$complemento,':Email' =>$email,':Senha' =>$senha));
echo $stmt-> rowCount();
}catch(PDOException $e){
echo 'Erro '.$e->getMessage();
}}
?>
Form
<html>
<head>
<title></title>
</head>
<body>
<form method="post" name="cliente" action="valida.php">
<h1>CADASTRO DE CLIENTES ODONTOCENTER</h1>
<br>
<p>id:
<input type="text" name="idcliente" readonly>
</p>
<p>Nome:
<input type="text" name="Nome">
</p>
<p>CPF:
<input type="text" name="CPF">
</p>
<p>Sexo
<input type="radio" name="Sexo" value="M">M
<input type="radio" name="Sexo" value="F">F
<p>
<p>Data de Nascimento:
<input type="text" name="DataNasc">
</p>
<p>Telefone:
<input type="text" name="Telefone">
</p>
<p>Cidade:
<input type="text" name="Cidade">
</p>
<p>Bairro:
<input type="text" name="Bairro">
</p>
<p>Rua:
<input type="text" name="NomedaRua">
</p>
<p>Número:
<input type="text" name="NumeroCasa">
</p>
<p>Complemento:
<input type="text" name="Complemento">
</p>
<p>Email:
<input type="text" name="Email">
</p>
<p>Senha:
<input type="password" name="Senha">
</p>
<p>
<input type="submit" value="Incluir" name="btnincluir">
<input type="submit" value="Alterar" name="btnalterar">
<input type="submit" value="Excluir" name="btnexcluir">
</p>
</form>
</body>
Good morning, man. If it’s a new record, you can start by removing :idclient that PDO and Mysql take care of themselves. Also make sure that you are sending to your database the same amount of columns that there are.
– Marcos Vinicius
Probably the error is, there is a more stated bind and one less informed. As Marcosvinicius said remove the
:idcliente
Insert.– rray