I've been trying php and I have some problems that i just cant solve with the parameters. If I try to save the parameter on BD by typing it saves otherwise if I try to send it straighten from the code it didn't work. That's my code.
<?php
class Cliente {
public $db;
public function __construct() {
$db = new Database();
$this->db = $db->instance();
$this-> sendDado();
}
public function sendDado(){
if ($_POST) {
try {
$query = $this->db->prepare("INSERT INTO PESSOA(nome, email, func) values(:nome,:email,:func)");
$query->bindValue(":nome", $_POST['nome'], PDO::PARAM_STR);
$query->bindValue(":email", $_POST['email'], PDO::PARAM_STR);
$query->bindValue(":func", $_POST["1"], PDO::PARAM_INT);
$query->execute();
echo "Enviado com sucesso";
} catch(PDOException $e) {
echo "Não foi possivel enviar";
}
}
}
?>
Not knowing the error message (often essential to know when debugging), I can only take a guess. $_POST["1"]
looks suspicious. Do you really have a POST variable with "1" (number one) as its name (is that even allowed)? Or are you trying to save the integer 1 as the value of "func" in the database? If yes, change that line to
$query->bindValue(":func", 1, PDO::PARAM_INT);