darkfreaks Posted January 14, 2009 Share Posted January 14, 2009 Fatal error: Cannot use object of type mysqli_result as array in /home/kabooc/public_html/user_profile.php on line 43 so how do i fix this ??? <?php $rank_check = 1; $page_title = "User Profile"; include "header.inc.php"; $db_server = "localhost"; $db_username = "kabooc_Bryce"; $db_password = "doom"; $db_name = "kabooc_pets"; $con=mysqli_connect($db_server,$db_username,$db_password); mysqli_select_db($con,$db_name); $members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'"); $members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'"); $profile_id = fetch("SELECT id FROM `members2` WHERE username = '$members[username]'"); $online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1"); if ($rank >= "5") { $iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1"); $membersIP = " ($iplog[ip_addr])"; } if (!$members[id]) { die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML"); } if ($members[rank] <= 1) { die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML"); } $gender = $members_profiles[gender]; $genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>"); $gender = $genderArray[$gender]; $mailSettings = $members_profiles[mail_settings]; $mailSettingsArray = array( //error line "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", "<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>", "");?> Link to comment https://forums.phpfreaks.com/topic/140843-can-not-use-object-as-type-mysqli_result-as-array/ Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 Please show use more code and the exact error message. Ken Link to comment https://forums.phpfreaks.com/topic/140843-can-not-use-object-as-type-mysqli_result-as-array/#findComment-737173 Share on other sites More sharing options...
darkfreaks Posted January 14, 2009 Author Share Posted January 14, 2009 ok added all code up to the error and fetch is a function that calls everything as mysqli_query(mysqli_fetch_array($connection,$query)). Link to comment https://forums.phpfreaks.com/topic/140843-can-not-use-object-as-type-mysqli_result-as-array/#findComment-737183 Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 What does the function "fetch()" do? Ken Link to comment https://forums.phpfreaks.com/topic/140843-can-not-use-object-as-type-mysqli_result-as-array/#findComment-737198 Share on other sites More sharing options...
darkfreaks Posted January 14, 2009 Author Share Posted January 14, 2009 it gets the query and puts it into an array so you do not have to call mysql_fetch_array later on. Link to comment https://forums.phpfreaks.com/topic/140843-can-not-use-object-as-type-mysqli_result-as-array/#findComment-737200 Share on other sites More sharing options...
darkfreaks Posted January 14, 2009 Author Share Posted January 14, 2009 Function Fetch: <?php function fetch($query) { $db_server = ""; $db_username = ""; $db_password = ""; $db_name = ""; $con=mysqli_connect($db_server,$db_username,$db_password); mysqli_select_db($con,$db_name); if ($result = mysqli_query($con,$query)) { if (mysqli_num_rows($result) == 1) { return mysqli_fetch_assoc($result); } else if (mysqli_num_rows($result) > 1) { while ($row = mysqli_fetch_assoc($result)) { $return[] = $row; } return $return; } return false; } } ?> Link to comment https://forums.phpfreaks.com/topic/140843-can-not-use-object-as-type-mysqli_result-as-array/#findComment-737344 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.