Getting no data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Todlerone
Forum Commoner
Posts: 96
Joined: Sun Oct 28, 2007 10:20 pm
Location: Hamilton, Ontario, Canada

Getting no data

Post by Todlerone »

Hello all. Thank-you in advance for any help/suggestions. I can't figure-out why this won't work.

Code: Select all

$idscores=safe_output($_POST["GameScores"]);
$query = "SELECT * FROM schedule09 WHERE game_id = $idscores";
$result=mysql_query($query);
$row=mysql_fetch_array ($result,MYSQL_NUM);
$Currentdate = $row[1];
 
When I echo $idscores before the $query I get the number I'm looking for. The correct data is in the schedule09 DB.

Thanks
Todlerone
Last edited by Todlerone on Sun May 10, 2009 6:25 pm, edited 2 times in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Getting no data

Post by John Cartwright »

You need to execute the query (mysql_query()), and fetch the results (mysql_fetch_assoc())
Todlerone
Forum Commoner
Posts: 96
Joined: Sun Oct 28, 2007 10:20 pm
Location: Hamilton, Ontario, Canada

Re: Getting no data

Post by Todlerone »

TY for your response John. I edited my original post to show more of the code. My query seems to get nothing back. The $idscores is the exact value I want and like I said the data in the DB is there under the primary value that I'm trying to extract. Is there something wrong with the query structure with the $idscores variable?

Todlerone
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Getting no data

Post by John Cartwright »

Try running this instead to give us some more information

Code: Select all

$idscores=safe_output($_POST["GameScores"]);
$query = "SELECT * FROM _schedule09 WHERE game_id = $idscores";
 
echo 'Query: '. $query .' <br />';
 
$result=mysql_query($query);
 
if (!$result) {
   echo 'Query Failed because: '. mysql_error() .'<br>';
}
 
echo 'Number rows found: '. mysql_num_rows($result) .'<br>';
 
while ($row = mysql_fetch_assoc($result)) {
   echo 'Row data: '. print_r($row, true) .'<br>';
}
Todlerone
Forum Commoner
Posts: 96
Joined: Sun Oct 28, 2007 10:20 pm
Location: Hamilton, Ontario, Canada

Re: Getting no data

Post by Todlerone »

It's an access denied error. This is for a Joomla site that I have made. I'm using my own code via a "JUMI" module. My problem seems to be when I had my own simple coded site I had an admin section that allowed a form to be populated with MySql DB content. You could select a date to add scores then it would direct you to another page (from the action of the form) Here you would enter the scores then the DB would be updated. I'm sure I have over killed the code doing this but it worked perfectly. With Joomla the form action call outs seem to be my problem. Is there a way for me to make one form the calls itself "PHP_SELF" that would have multiple levels of forms? For example:
if date selected do this;
if date selected and scores entered do this
else show form.
I hope I'm making sense. I know there is some Javascript that would help but I don't know any Javascript and would prefer to do it with PHP as I can usually make my way around the coding (if not eventually). I currently have one form (select a date to enter scores for) that calls another form (enter the scores for selected game date) that then calls another php file that updates the DB. Can it be put into one php file or should I not try this?

TY John
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Getting no data

Post by John Cartwright »

You are getting the access denied error because you have not provided the correct database details/credentials, and/or your user does not have permission to execute the query (likely the former).
enna
Forum Newbie
Posts: 8
Joined: Thu Jun 04, 2009 4:54 am

Re: Getting no data

Post by enna »

Todlerone wrote:Hello all. Thank-you in advance for any help/suggestions. I can't figure-out why this won't work.

Code: Select all

$idscores=safe_output($_POST["GameScores"]);
$query = "SELECT * FROM schedule09 WHERE game_id = $idscores";
$result=mysql_query($query);
$row=mysql_fetch_array ($result,MYSQL_NUM);
$Currentdate = $row[1];
 
When I echo $idscores before the $query I get the number I'm looking for. The correct data is in the schedule09 DB.

Thanks
Todlerone
try changing this
$query = "SELECT * FROM schedule09 WHERE game_id = $idscores";

to this
$query = "SELECT * FROM schedule09 WHERE game_id = '$idscores'"; -->i placed apostrophes
Post Reply