vhdz04 vhdz04 - 4 months ago 20x
PHP Question

Retrieve a value from sqli_query

I am trying to retrieve the highest userID in my sql table. I am using sqli_query function in PHP. I know this function returns an object. How can I assign the returned userID to a variable?

$query = "SELECT max(UserID) FROM userinfo";
$highID = mysqli_query($conn, $query);

if (!$highID) {
printf("Error: %s\n", mysqli_error($conn));

while($rows = mysqli_fetch_array($highID, MYSQL_ASSOC))

echo "{$rows['UserID']}";

this is the error I get

Notice: Undefined index: UserID in C:\Apache24\htdocs\dbpractice\info.php on line 165

$query = "SELECT max(UserID) as maxUserID FROM userinfo";

Now you can use