1
Hello, I am working with some related tables and I can not insert the values in the next rabela, I found that I need to recover the last id inserted in the still can not use it, without the relation the tables work perfectly. Follow commands. OBS: Do not execute it does not return any error.
Customer class
public function sendDado(){
if($_POST){
try{
$query = $this->db->prepare("INSERT INTO CLIENTE(nome, email) values(:nome,:email)");
$query->bindValue(":nome", $_POST['nome'], PDO::PARAM_STR);
$query->bindValue(":email", $_POST['email'], PDO::PARAM_STR);
$query->execute();
echo "Enviado com sucesso";
header('Location: telefone.tpl.php');
//return ($query);
}catch(PDOException $e){
echo "Não foi possivel enviar";
}
}else{
echo "";
}
return $query;
}
Telephone class
public function sendDado($scan){
//$scan = new Cliente();
//$esse->scan = $scan->sendDado();
//$esse-> sendDado($scan);
$u_id = $this->db->query("SELECT LAST_INSERT_ID()");
if($u_id != null){
if($_POST){
try{
$query = $this->db->prepare("INSERT INTO TELEFONES(rel_id,telefone,celular,ramal) values (:u_id,:telefone,:celular,:ramal)");
$query->bindValue(":u_id",$_POST['u_id'],PDO::PARAM_INT);
$query->bindValue(":telefone",$_POST['telefone'],PDO::PARAM_INT);
$query->bindValue("celular",$_POST['celular'],PDO::PARAM_INT);
$query->bindValue("ramal",$_POST['ramal'],PDO::PARAM_INT);
$query->execute();
echo "Enviado com sucesso";
//if(){
header('Location: emp.tpl.php');
//)else{
//header('Location: ');
//}
}catch(PDOException $e){
echo 'Informacao não pode ser enviada';
}
}
}else{
echo $u_id;
//header('Location: cliente.tpl.php');
}
}
Wouldn’t it be better to take php? $last = db->lastInsertId(); after running
– Felipe Duarte