Jump to content

Select?!


Cooper94

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.