mysql_fetch_object(): supplied argument is not a valid MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jimgym1989
Forum Newbie
Posts: 10
Joined: Thu May 14, 2009 8:31 am

mysql_fetch_object(): supplied argument is not a valid MySQL

Post by jimgym1989 »

Hi there!
I'm new in PHP
I'm trying to connect php and adobe flex(mxml)
why does it have an error that says: Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\wamp\www\irmnewest-debug\studinfo.php on line 11
I just want to display those data who have a username of variable $varUser in my datagrid in adobe flex.

Code: Select all

<?php
 
include("connection.php");
$varUser= mysql_real_escape_string($_POST["untext"]);
 
$query  = "SELECT username, studentid, firstname, lastname, course, year FROM student where username = $varUser";
 
$result = mysql_query($query);
 
print "<datas>";
    while ($recordset = mysql_fetch_object($result) ){
        print "<data><username>".$recordset->username."</username>
        <id>".$recordset->studentid."</id>
           <ln>".$recordset->lastname."</ln>
               <fn>".$recordset->firstname."</fn>
        <kurs>".$recordset->course."</kurs>
        <yr>".$recordset->year."</yr>
        </data>";
    }
print "</datas>";
?>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: mysql_fetch_object(): supplied argument is not a valid MySQL

Post by jackpf »

Put "or die(mysql_error())" after the query.

Also, if $varUser isn't an int, it'll need quoting.
frao_0
Forum Commoner
Posts: 27
Joined: Sat Aug 08, 2009 3:52 am
Location: Toulouse, France

Re: mysql_fetch_object(): supplied argument is not a valid MySQL

Post by frao_0 »

2 things that might help

var_dump $result to see if the mysql_query returned false

specify the link referer in mysql_query

and as jackpf said, a mysql_error()
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: mysql_fetch_object(): supplied argument is not a valid MySQL

Post by Benjamin »

Strings must be encapsulated in single quotes:

Code: Select all

$query  = "SELECT username, studentid, firstname, lastname, course, year FROM student where username = '$varUser'";
Post Reply