Help - Search - Members - Calendar
Full Version: Php Not Printing $row Array Element
BleepingComputer.com > Internet & Networking > Web Site Development
   
Glunn11
Hello BC!
I have been playing with PHP to design a basic website that I want to use to keep track of a virtual casino's "credits." However, I am stuck at a problem. I have a table called 'light' with the columns 'username', 'credits', and 'last_mod'. I can get the following page to echo the username and credits values of a certain row, but not the last_mod value. I am not sure why.
Any help would be appreciated!

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Lookup</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Account Lookup</h1>
<a href="member-index.php">Back to Index</a> | <a href="lookup.php">Back to Lookup</a> | <a href="logout.php">Logout</a>
<?php
include 'opendb.php';
if(!get_magic_quotes_gpc())
{
$Username = mysql_real_escape_string($_POST['username']);
$acctType = mysql_real_escape_string($_POST['acctType']);
}
else
{
$Username = $_POST['username'];
$acctType = $_POST['acctType'];
}

$qry = "SELECT credits FROM $acctType WHERE username='$Username'";
$result = mysql_query($qry);

if (mysql_num_rows($result)==0)
{
echo "<p><font size='+1' color='red'>$Username does not have a $acctType LEGACY account - remember that the database is CaSe

SeNsItIvE</font></p><p><a href='lookup.php'>Try Again</a>";
}
else
{
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC))
{
echo $row['last_mod'];
if (($acctType == 'light') && ($row['credits'] < 1))
{
$output = "Inform the bettor that his or her account balance has fallen below the minimum. This occurred at " . $row['last_mod'] . ", and the

bettor has three business days to refill his or her account after this date before it will be automatically closed. This means that if the below-

minimum status of the account occurred on October 3, he or she would have until the casino closes on October 6 to add more to his or her

account.";
}
else if (($acctType == 'gambler') && ($row['credits'] < 15))
{
$output = "Inform the bettor that his or her account balance has fallen below the minimum. This occurred at " . $row['last_mod'] . ", and the

bettor has three business days to refill his or her account after this date before it will be automatically closed. This means that if the below-

minimum status of the account occurred on October 3, he or she would have until the casino closes on October 6 to add more to his or her

account. A Gambler account closure will take a 5-credit fee, and any remaining credits will then be returned to his or her donations room.";
}
else if (($acctType == 'high_roller') && ($row['credits'] < 150))
{
$output = "Inform the bettor that his or her account balance has fallen below the minimum. This occurred at " . $row['last_mod'] . ", and the

bettor has three business days to refill his or her account after this date before it will be automatically closed. This means that if the below-

minimum status of the account occurred on October 3, he or she would have until the casino closes on October 6 to add more to his or her

account. A High Roller account closure will take a 10-credit fee, and any remaining credits will then be returned to his or her donations room.";
}
else
{
$output = "";
}
echo "<p><font size='+1'>Current LEGACY Credits on " . $Username . ": " . $row['credits'] . "</font><img src='http://www.habbo.com/habbo-

imaging/avatarimage?user=" . $Username . "&action=&direction=4&head_direction=4&gesture=&size=l' alt='" . $Username . " avatar'></p><p>" .

$output . "</p><p>&nbsp;</p><p>If you would like to modify this, please enter the new amount here:</p><p><form id='modify' name='modify'

method='post' action='mod.php'><input name='newAmount' type='text' class='textfield' id='newAmount' /><input name='acctType' type='hidden'

id='acctType' value='" . $acctType . "' /><input name='username' type='hidden' id='username' value='" . $Username . "' /><input name='submit'

type='submit' id='submit' value='Modify' /></form></p>";
}
}
include 'closedb.php';
?>
</body>
</html>
groovicus
Have you accessed mysql from the command line to verify that the field is even being populated?
Glunn11
Hey groovicus! Thank you for your reply.
Yes, that is my whole point of confusion. The column last_mod, which is a char(8) column, does exist, and with the row in dispute, it has the value '07/07/08'. I have triple-checked this with the MySQL command line.
Nonetheless, I did add that column later on in the table's development, with the command:
ALTER TABLE light ADD COLUMN last_mod char(8) NOT NULL;

I have tried deleting and recreating the column, but that does not seem to resolve the issue.
The commands echo $row['username'] and echo $row['credits'] both return the desired values, but echo $row['last_mod'] returns nothing.

The table (dashes signify spaces and do not exist in the actual table):

username|credits|last_mod
----------------------------------
Glunneh--|---0---|07/07/08
groovicus
Your SQL query is only selecting the credits from the table, not the credits and last_mod. Apparently after you altered your table, you forgot to update your SELECT statement.

EDIT: You are not getting the user name from the database either. That is coming from the http session, so the fact that you can echo the user name is not a symptom. smile.gif
Glunn11
ohmy.gif
I never would've thought of that! Now that I think about it, I never really tested $Username on that PHP file.
Ah, groovicus, what would this board be without you?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.