Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Php Not Printing $row Array Element


  • Please log in to reply
4 replies to this topic

#1 Glunn11

Glunn11

  • Members
  • 262 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Idaho
  • Local time:09:38 AM

Posted 07 July 2008 - 05:46 PM

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!

[codebox]<!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>[/codebox]

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:38 AM

Posted 07 July 2008 - 06:28 PM

Have you accessed mysql from the command line to verify that the field is even being populated?

#3 Glunn11

Glunn11
  • Topic Starter

  • Members
  • 262 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Idaho
  • Local time:09:38 AM

Posted 07 July 2008 - 06:48 PM

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

Edited by Glunn11, 07 July 2008 - 06:51 PM.


#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:38 AM

Posted 07 July 2008 - 08:40 PM

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. :thumbsup:

#5 Glunn11

Glunn11
  • Topic Starter

  • Members
  • 262 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Idaho
  • Local time:09:38 AM

Posted 07 July 2008 - 09:47 PM

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

Edited by Glunn11, 07 July 2008 - 09:49 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users