Hello i have build a PHP file which is adding entries in a mysql database. My php call an include function file to add data (function sqlQuery)
I'm using incermental ID and i'd like to get the Id number just created. i'm trining unsing mysqli_insert_id() but it did not reply anything
my php file :
$query = "INSERT into publis (entry, bibTex";
foreach($fields as $field)
if (isset($_GET["$field"]))
$query .= ", $field";
$query .= ") VALUES ('$_GET[entry]', '$bibTex'";
foreach($fields as $field)
if (isset($_GET["$field"]))
$query .= ", '".LaTeXToIso(addslashes($_GET["$field"]))."'"; // Ajout de addslashes par Vincent le 26 juillet 2017
$query .= ")";
debug($query);
sqlQuery($query);
$id = mysqli_insert_id();
my function "sqlQuery" (in an other file funtions.php)
function sqlQuery($query)
{
$database="basilic";
$host="localhost";
$name="xxx";
$password="xx";
if (!$link = mysqli_connect($host, $name, $password)){
$msg = "Unable to connect to mySQL server\nHost=$host, Name=$name\n";
sendMessage($msg);
die($msg . "Administrator has been warnedb prb connexion.");
}
if (!mysqli_select_db($link, $database)) {
sendMessage("Unable to select $database mySQL database");
echo("Unable to select mySQL database. Administrator has been warned.");
die("</body>\n</html>\n");
}
if ($result = mysqli_query($link,$query))
return $result;
else {
sendMessage("Invalid sql query : $query");
echo("Invalid Sql query. Administrator has been warned\n");
echo("Debug : Invalid Sql query : <br />\n<code>$query</code>\n");
die("</body>\n</html>\n");
}
}
the entry is well created in the database
Can you help me to get this ID
thanks a lot and sorry for my english
try to get the last ID created