Forum Moderators: coopster

Message Too Old, No Replies

Debugging error :(

         

adammc

6:54 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Hi guys,

Anyone know why I am getting a "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result " error on this?

[php]
// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
$result = mysql_query($query);
while($r = mysql_fetch_assoc($result))
{
[/php]

Habtom

6:59 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'

Wrong query may be, check your field names.

vincevincevince

7:03 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
$result = mysql_query($query);
while($r = mysql_fetch_assoc($result))
{

You are running mysql_query() twice there.

You want:

// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
while($r = mysql_fetch_assoc($query))
{

adammc

7:03 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Hi Habtom,
no luck, all field names seem correct?

Any other ideas?

adammc

7:06 am on Aug 23, 2007 (gmt 0)

10+ Year Member



vincevincevince,
Same thing.. still getting error :(

vincevincevince

7:06 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What error you do get now? Did you remove that line and make the change from $result to $query on your loop line?

adammc

7:09 am on Aug 23, 2007 (gmt 0)

10+ Year Member



// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
while($r = mysql_fetch_assoc($query))
{

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

on this line:
while($r = mysql_fetch_assoc($query))

Habtom

7:11 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My guess is still in the query:

Put the mysql_query and mysql_fetch_assoc the way it was and

. .. replace this with the query:
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='". $user ."'") or die(mysql_error());

. . . put this line after it, that is for test and see how the query looks like when printed:
echo "SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='". $user ."'";

Hab

adammc

7:19 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Habtom,

this was the result of the echo:

SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='zzzzzzz'

Still getting that error though :(

Habtom

7:21 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not sure what else it could be.

How about just using mysql_fetch_array() instead of the assoc?

adammc

7:24 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Even this is producing same error:

$query = "SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'";
$result = @mysql_query ($query) or die(mysql_error());
while($r=mysql_fetch_array($result))
{

vincevincevince

7:27 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



adammc...
while($r=mysql_fetch_array($result))

I changed that $result in $query, check carefully above...
while($r=mysql_fetch_array($query)) 

The other possible explaination is that you are overwritting the variable $query during your loop. There should not be anything written $query= within the while { } loop... if there is, change it to use another variable name ($queryb)

Habtom

7:30 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



vincevincevince, indeed was right you had two mysql_query in there. Didn't even notice it myself.

All the ones mentioned till, I have put them in one block. Can you try copying the following as it is, and see if you still get an error?

// Get the student info from DB
$query = "SELECT student_id, type, guardianship, first_name, last_name, agent_number FROM students WHERE username='". $user ."'";
$result = mysql_query($query);
while($rows = mysql_fetch_array($result))
{

adammc

7:38 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Yahhhhhhhh!
That was it vince :)

"The other possible explaination is that you are overwritting the variable $query during your loop. There should not be anything written $query= within the while { } loop... if there is, change it to use another variable name ($queryb"

I had 2 other $query and $result Variables which I changed.

Thank you both so much for your help.

vincevincevince

7:38 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad to have been of help.