Nematode128 Posted April 6, 2020 Share Posted April 6, 2020 Hello I'm trying to set up a user area for my site where it displays the current logged in users ranking and other information in the future. <? ini_set('display_errors', 1); require_once "header.php"; $sql = "SELECT * FROM users WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ mysqli_stmt_bind_param($stmt, 's', $_SESSION['username']); if(mysqli_stmt_execute($stmt)){ $info = mysqli_fetch_array($stmt); echo "Current rank:" . $info['rank']; } else { echo "Can't find user"; } } mysqli_stmt_close($stmt); ?> That's the code I currently have but it gives me the error "but get an error message of mysqli_fetch_array() expects parameter 1 to be mysqli_result" Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/ Share on other sites More sharing options...
ginerjm Posted April 6, 2020 Share Posted April 6, 2020 Look at the line it points you to and then check your code on that line. Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/#findComment-1576437 Share on other sites More sharing options...
Nematode128 Posted April 6, 2020 Author Share Posted April 6, 2020 4 minutes ago, ginerjm said: Look at the line it points you to and then check your code on that line. This is the code on the line it points to " $info = mysqli_fetch_array($stmt);" Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/#findComment-1576441 Share on other sites More sharing options...
ginerjm Posted April 6, 2020 Share Posted April 6, 2020 Hmmm.... My copy of the PHP.net manual does not have that function in it. But in most cases one has to provide the results var and you are not, which is what the message is telling you. Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/#findComment-1576443 Share on other sites More sharing options...
Nematode128 Posted April 6, 2020 Author Share Posted April 6, 2020 @ginerjm https://www.php.net/manual/en/mysqli-result.fetch-array.php that's what I found about the fetch array on PHP.net. so for the results var it would be something like like "$results = mysqli_store_result($stmt) or am I misunderstanding? Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/#findComment-1576446 Share on other sites More sharing options...
mac_gyver Posted April 6, 2020 Share Posted April 6, 2020 fetching data from a mysqli prepared query doesn't work the way you are used to for fetching data from a query. you will need to consult the documentation for the extra code necessary, or you can switch to the much simpler PDO database extension, which does work for fetching the data from a prepared query in the way you are used to. also, if you use exceptions for database statement errors, and in most cases let php catch and handle the exception, you won't have to add logic (or can remove the logic you have now) that's testing the result of the prepare() and execute() statements, simplifying the code. Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/#findComment-1576447 Share on other sites More sharing options...
Nematode128 Posted April 6, 2020 Author Share Posted April 6, 2020 Solved Quote Link to comment https://forums.phpfreaks.com/topic/310480-help-displaying-info-from-a-users-database-table/#findComment-1576450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.