Currently I'm creating a commentary system and sometimes I must verify if the ID that will be inserted in the database exists or not. If not exists, just return, else, generate again.
Here is my function:
function checkId($n) {
global $mysqli;
$query = mysqli_query($mysqli, "SELECT id FROM comments WHERE id = ".$n.""); //line error
if (!$query) {
die('Error: ' . mysqli_error($mysqli));
}
if(mysqli_num_rows($query) > 0){
checkId($n++);
return;
} else {
return $n;
}
}
Probably you gonna tell me to use AUTO_INCREMENT
, but in this situation I'm not able to do.
The error is: Fatal error: Maximum function nesting level of '100' reached, aborting!
I have tried fix it myself but I'm unable, can you help me? Thank you.