首页 > 解决方案 > I can't get the ID variable using mysqli_insert_id

问题描述

I'm trying to execute this sql query but it doesn't insert in the correct ID. I'm trying getting the last ID using mysqli_insert_id but without result. Thanks for the help!

$sql = "insert into desechados 
                (rutrep, rutempr, nombreusu, apematusu, 
                apepatusu, nombempr, giroempr, direempr, 
                corrusua, numeusua) 
        select rutrepr, rutempr, nombusua, apematus, 
                apepatus, nombempr, giroempr, direempr, 
                corrusua, numeusua 
        from usuario 
        where rutrepr='".$_SESSION['rutrep']."'";

if(mysqli_query($con,$sql)){
    $last_id = mysqli_insert_id($con);
}

$razonrechazo = $_POST['oculto'];   

$sql1 = "insert into desechados (razonrechazo) values ('$razonrechazo') where (iddesechados=".$last_id.") ";
mysqli_query($con, $sql1);

标签: phpsqlmysqli

解决方案


推荐阅读