Minklet Posted August 5, 2010 Share Posted August 5, 2010 I think I put this in the wrong forum, as it seems to be more of a php problem (I think) I'm trying to populate a profile page with information from the database. Really bizarrely, every $row variable that isn't null returns as 'website', which is the database username. I have absolutely no idea why this is. It might be worth noting I have just changed hosts...the only thing I can think might make a difference. Any help would be great, thankyou $query = "SELECT * FROM member WHERE username='$member'"; $result = mysqli_query ($dbc, $query) or trigger_error ("query: $query\n<br />MySQL Error: " . mysqli_error($dbc)); if ($result) { while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $member_id = $row['member_id']; $username = $row['username_id']; $photo = $row['photo']; $about = $row['about']; $slink = $row['soundcloud_link']; $mlink = $row['mixcloud_link']; $flink = $row['facebook_link']; $dlink = $row['divshare_link']; $mylink = $row['myspace_link']; $plink = $row['postbocks_links']; $website = $row['personal_website']; $type = $row['member_type']; $status = $row['status']; } } } I've echo'd the $query and put the result into sql directly and it comes out fine. Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/ Share on other sites More sharing options...
Skewled Posted August 5, 2010 Share Posted August 5, 2010 Try this: $query = "SELECT * FROM member WHERE username='$member'"; $result = mysqli_query ($dbc, $query) or trigger_error ("query: $query\n<br />MySQL Error: " . mysqli_error($dbc)); $row = mysqli_fetch_array($result) // List out your variables here // Then somewhere you can echo them out to format your page. Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/#findComment-1095649 Share on other sites More sharing options...
Minklet Posted August 5, 2010 Author Share Posted August 5, 2010 Still the same problem sadly Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/#findComment-1095650 Share on other sites More sharing options...
wildteen88 Posted August 5, 2010 Share Posted August 5, 2010 Add echo '<pre>'.print_r($row, true).'</pre>'; After $row = mysqli_fetch_array($result); Post the output here. Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/#findComment-1095651 Share on other sites More sharing options...
Minklet Posted August 5, 2010 Author Share Posted August 5, 2010 Array ( [member_id] => 1 [member_firstname] => Michael [member_lastname] => Mallett [member_dateregistered] => 2010-08-05 11:05:25 [password] => cca961192cdfac00b66a8e2ad9337ad9250ab11f [username_id] => Shiverman [activate_code] => [photo] => [fb_userid] => [fb_proxiedemail] => [about] => [soundcloud_link] => [facebook_link] => [divshare_link] => [mixcloud_link] => [myspace_link] => [postbocks_links] => [personal_website] => [member_type] => 1 [status] => 1 => Mike@Generalpie.com [active] => ) So it's kicking out the right values... Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/#findComment-1095658 Share on other sites More sharing options...
Minklet Posted August 5, 2010 Author Share Posted August 5, 2010 It's actually nothing to do with the sql query. I've just tried putting a string into the variables and it is still coming up with 'website'. If it's not the database username then I have no idea what it is. It echo's the correct values when it is inside the if ($result) braces, so it seems to be a scope thing...is this a php setting? Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/#findComment-1095669 Share on other sites More sharing options...
wildteen88 Posted August 5, 2010 Share Posted August 5, 2010 Where are you echoing out the individual variables? The code you posted above is not contained within a function is it? If it is then you may have a variable scope issue. But without seeing more code we wont know for sure. Quote Link to comment https://forums.phpfreaks.com/topic/209915-really-odd-mysqli_fetch_array-behaviour/#findComment-1095670 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.