-1
I have an insert page, as soon as I click insert new accommodation, the system should insert some ready data, but on the same page I need to recover the last id, so that I can complete the other information of the form, as if I were editing the information.
In mysqli
I managed to, more need to transform to PDO, and I’m having difficulties, follows below the code.
$imagem="produto.png";
$insert=mysqli_query($con,"insert into tbl_acomodacoes (acomodacao_imagem, acomodacao_situacao) values ('$imagem','0')");
$sql_last=mysqli_query($con,"select LAST_INSERT_ID(acomodacao_id) as last from tbl_acomodacoes order by acomodacao_id desc limit 0,1");
$rw=mysqli_fetch_array($sql_last);
$acomodacao_id=intval($rw['last']);
$sql=mysqli_query($con,"select * from tbl_acomodacoes where acomodacao_id='$acomodacao_id' limit 0,1");
$count=mysqli_num_rows($sql);
if ($count==0){
//header("location: acomodacao.php");
//exit;
}
$rw=mysqli_fetch_array($sql);
$titulo=$rw['acomodacao_titulo'];
$slug=$rw['acomodacao_slug'];
$link=$rw['acomodacao_link'];
$texto=$rw['acomodacao_texto'];
$quantidade=$rw['acomodacao_quantidade'];
$imagem=$rw['acomodacao_imagem'];
$situacao=intval($rw['acomodacao_situacao']);
Dear Samuel, why do you need this in PDO? What’s wrong with mysqli?
– Guilherme Nascimento