0

I am trying to get an auto increment so that when users are added to a Database the ID goes up by 1 each time so all are unique.

But I am getting: Notice: Trying to get property of non-object in /var/www/html/beta/ai.php on line 89

Line 89 being "return $result->ai;"

function getLastIncrement() {
$dbHost = "localhost";
$dbUsername = "root";
$dbPassword = "PASS";
$dbName   = "beta";
$conDb = mysqli_connect($dbHost, $dbUsername, $dbPassword, $dbName);
$result = mysqli_query($conDb,"SELECT `AUTO_INCREMENT` as `ai` FROM  INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'beta' AND TABLE_NAME = 'ml_rank'");
$result = mysqli_fetch_object($result);
return $result->ai;

}

Henry D.
  • 41
  • 7
  • 1
    If field is autoincrement then new record always has new value __autoincremented__ by one. – u_mulder Sep 29 '18 at 16:27
  • 1
    Possible duplicate of [PHP mySQL - Insert new record into table with auto-increment on primary key](https://stackoverflow.com/questions/7492145/php-mysql-insert-new-record-into-table-with-auto-increment-on-primary-key) – Nigel Ren Sep 29 '18 at 16:27

0 Answers0