0
Every time I try to catch the id
of that first INSERT
, for mysqli_insert_id()
, he returns 0
in the second Insert and returns the correct number in the header below, which can be?
require_once('../connects/connection.php');
session_name(md5('inv_log'));
session_start();
$evntowner = $_SESSION['uid'];
if(isset($_POST['evntnamesu']) && isset($_FILES['bgenvtpopup'])){
$eventname = $_POST['evntnamesu'];
$eventtype = $_POST['evntypesu'];
$eventaccess = $_POST['evntaccsu'];
$imagem = $_FILES["bgenvtpopup"];
if(empty($imagem['name'])){
$limit = "";
}else{
$ext = pathinfo($imagem["name"], PATHINFO_EXTENSION);
$pasta = "../eventimgs/bg2/";
$limit = $pasta.md5($imagem["name"].mt_rand()).".".$ext;
move_uploaded_file($imagem["tmp_name"], $limit);
}
$eventprice = $_POST['input-money'];
$eventlocal = $_POST['localnamesu'];
$eventlocaladrs = $_POST['adrslocalsu'];
$starTimeHorValue = $_POST['startTimeHor'];
$starTimeMinValue = $_POST['startTimeMin'];
$endTimeHorValue = $_POST['endTimeHor'];
$endTimeMinValue = $_POST['endTimeMin'];
$starteventtime = $starTimeHorValue.':'.$starTimeMinValue;
$endeventtime = $endTimeHorValue.':'.$endTimeMinValue;
$eventday = $_POST['evntdayvlpop'];
$eventmonth = $_POST['evntmonthvlpop'];
$eventyear = $_POST['evntyearvlpop'];
$evntfulldate = $eventyear.'-'.$eventmonth.'-'.$eventday;
$eventdescr = $_POST['descriptevent'];
$sql = "INSERT INTO `events` (`event_id`, `event_owner_id`, `event_name`, `event_type`, `event_access`, `event_bg2`, `event_price`, `event_local`, `event_local_adrs`, `event_time_start`, `event_time_end`, `event_day`, `event_descr`) VALUES (NULL, '$evntowner', '$eventname', '$eventtype', '$eventaccess', '$limit', '$eventprice', '$eventlocal', '$eventlocaladrs', '$starteventtime', '$endeventtime', '$evntfulldate', '$eventdescr')";
$run = mysqli_query($connection, $sql);
$last_id = mysqli_insert_id($connection);
}
$ids = $_POST['invitedVal'];
$party_id = $last_id;
if(empty($ids)){
}else{
$idsDivide = explode(',', $ids);
for($i = 0;$i < count($idsDivide); $i++){
mysqli_query($connection, "INSERT INTO invitations (inv_id, party_id, user_id, inv_status, inv_code, inv_user_status) VALUES (null, '$party_id', '$idsDivide[$i]', '1', '0', '0')");
}
}
/*Redirect by function on geteventinfos.js:469*/
Has a
}
lost in the code, the first Insert does not give error?– rray
It’s because there’s more code on top, which I cut to make it easier to understand
– Vinnicius Pereira
Make a:
var_dump(mysqli_insert_id($connection));
– rray
The first Insert is inside a
if
. Are you sure he’s being executed?– bfavaretto
yes, because it inserts things inside the db so that comes the mysqli_insert_id returning 0
– Vinnicius Pereira