Cooper94 Posted April 3, 2009 Share Posted April 3, 2009 <?php include 'db.php'; session_start(); $result = mysql_query("SELECT * FROM players WHERE account_id = '{$_SESSION['username']}' "); $num = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { echo "$row[name]"; } ?> Is there a reason why it isnt grabbing the information from the database? Thank You Quote Link to comment https://forums.phpfreaks.com/topic/152464-select/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 3, 2009 Share Posted April 3, 2009 Maybe $_SESSION['username'] is empty so the query does not match any rows. What have you done to troubleshoot what it is doing? Are you debugging this on a system where error_reporting is set to E_ALL and display_errors is set to ON so that you get immediate feedback from errors php finds? Quote Link to comment https://forums.phpfreaks.com/topic/152464-select/#findComment-800719 Share on other sites More sharing options...
mrMarcus Posted April 3, 2009 Share Posted April 3, 2009 use this instead .. $result = mysql_query("SELECT * FROM players WHERE account_id = '{$_SESSION['username']}' ") or die (mysql_error()); or just echo out your query .. echo $result; then you can see what's really going on. Quote Link to comment https://forums.phpfreaks.com/topic/152464-select/#findComment-800759 Share on other sites More sharing options...
Maq Posted April 3, 2009 Share Posted April 3, 2009 First off, are you sure you should be comparing account_id and username? Do you have a userid in the SESSIONs array that you should be using instead? use this instead .. $result = mysql_query("SELECT * FROM players WHERE account_id = '{$_SESSION['username']}' ") or die (mysql_error()); or just echo out your query .. echo $result; then you can see what's really going on. That would echo out the resource ID, not the query. If you want to echo out the query you need to put it into a string first. $sql = "SELECT * FROM players WHERE account_id = '{$_SESSION['username']}'"; echo "Your query: " . $sql; $result = mysql_query($sql) or die(mysql_error()); $num = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/152464-select/#findComment-800771 Share on other sites More sharing options...
mrMarcus Posted April 3, 2009 Share Posted April 3, 2009 First off, are you sure you should be comparing account_id and username? Do you have a userid in the SESSIONs array that you should be using instead? use this instead .. $result = mysql_query("SELECT * FROM players WHERE account_id = '{$_SESSION['username']}' ") or die (mysql_error()); or just echo out your query .. echo $result; then you can see what's really going on. my bad .. wasn't even paying attention to that. That would echo out the resource ID, not the query. If you want to echo out the query you need to put it into a string first. $sql = "SELECT * FROM players WHERE account_id = '{$_SESSION['username']}'"; echo "Your query: " . $sql; $result = mysql_query($sql) or die(mysql_error()); $num = mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/152464-select/#findComment-800772 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.