Every time I try to get the id
of that first INSERT
, by mysqli_insert_id()
, it returns 0
in the second insert and returns the correct number in the header below, what 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*/