$insert = "INSERT INTO event_tracker_table (event_name, event_location, location_number, event_creator_username, event_creator_email)
VALUES (
'".$_POST['event_name']."',
'".$_POST['event_location']."',
'".$_POST['location_number']."',
'".phpCAS::getAttribute('uid')."',
'".phpCAS::getAttribute('mail')."'
)";
$mysqli->query($insert);
如何获得由MySQL生成的此自动增量?我试过这个但是它没有用:
$statement = $mysqli->query($insert);
echo $statement->insert_id;
答案 0 :(得分:6)
Insert id是MYSQLI对象的属性,而不是MYSQLI结果对象:
$statement = $mysqli->query($insert);
echo $mysqli->insert_id; // correct
echo $statement->insert_id; //not correct
答案 1 :(得分:0)