Drezard Posted May 10, 2008 Share Posted May 10, 2008 Is there anything wrong with this? as in code wise? The mysql_fetch_array() is failing. Code: $query = "SELECT * FROM user_profiles WHERE user_id='$user_id'"; $result = mysql_query($query); $array = mysql_fetch_array($result); $name = $array[1]; $email = $array[2]; $location = $array[3]; Daniel Quote Link to comment https://forums.phpfreaks.com/topic/104994-mysql_fetch_array-problems/ Share on other sites More sharing options...
micmania1 Posted May 10, 2008 Share Posted May 10, 2008 You may have an error in your query. Try if ($result) { $array = mysql_fetch_array($result); } else { echo mysql_error(); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/104994-mysql_fetch_array-problems/#findComment-537420 Share on other sites More sharing options...
psychowolvesbane Posted May 10, 2008 Share Posted May 10, 2008 Is there anything wrong with this? as in code wise? The mysql_fetch_array() is failing. Code: $query = "SELECT * FROM user_profiles WHERE user_id='$user_id'"; $result = mysql_query($query); $array = mysql_fetch_array($result); $name = $array[1]; $email = $array[2]; $location = $array[3]; Daniel With the Array you need to use: $name = $array['Name']; (or whatever field name it is) $email = $array['Email']; $location = $array['Location']; BTW with an array it would actually start at 0 instead of 1, so 0,1,2 not 1,2,3. Quote Link to comment https://forums.phpfreaks.com/topic/104994-mysql_fetch_array-problems/#findComment-537441 Share on other sites More sharing options...
phorcon3 Posted May 10, 2008 Share Posted May 10, 2008 <?php $a=mysql_query("SELECT `name`,`email`,`location` FROM `user_profiles` WHERE `user_id` = '$user_id'"); $b=mysql_fetch_assoc($a) or mysql_error(); echo 'Name: '.$b['name'].'<br />'; echo 'Email: '.$b['email'].'<br />'; echo 'Location: '.$b['location']; ?> thats how id do it... Quote Link to comment https://forums.phpfreaks.com/topic/104994-mysql_fetch_array-problems/#findComment-537448 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.