I’ve created a function in php to add some information to a table. However the ID gets created upon entry. But I need that Id in order to perform another task, but I’m not actually sure how to get that entry.
SO my function is this:
addSkillset($agent, $computing, $tactical, $driving);
Which does this:
function addProperty($agent, $computing, $tactical, $driving) {
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
if (!$mysqli) {
die('There was a problem connecting to the database.');
}
else {
$query = "INSERT INTO Skillset VALUES (NULL, '$agent', '$computing', '$tactical', '$driving')";
}
if ($Results = mysql_query($query)){
echo "added";
}
$mysqli->close();
}
So in this query, the ‘NULL’ bit is what I’m trying to identify and return.
I assume I would have to put:
if ($Results = mysql_query($query)){
$somesortofvariable = somesortofcommand;
return $somesortofvariable;
}
But I’m not totally sure.
You are looking for mysqli_insert_id()