dimanche 17 juillet 2016

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: %sn", mysqli_error($conn));
    exit();
}

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

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

this is the error I get

Notice: Undefined index: UserID in C:Apache24htdocsdbpracticeinfo.php on line 165

Aucun commentaire:

Enregistrer un commentaire