Jump to content

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/152464-select/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/152464-select/#findComment-800719
Share on other sites

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);

 

Link to comment
https://forums.phpfreaks.com/topic/152464-select/#findComment-800771
Share on other sites

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);

 

Link to comment
https://forums.phpfreaks.com/topic/152464-select/#findComment-800772
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.