Click to See Complete Forum and Search --> : mysql Resource id #3?


conputerguy99
10-20-2005, 10:44 AM
When I run this query in my GUI database manager, this code gives me ShaRon, but with my php page, it returns Resource id #3. Does anyone know what this means?

SELECT pass FROM customers WHERE name = '$name'

Also, when I quote any of the things other than $name, then it throws me an error saying it's improper sql syntax.

tirebiter
10-20-2005, 11:46 AM
Are you using mysql_fetch_array() to get the data from the query?

$query=mysql_query("SELECT pass FROM customers WHERE name = '$name'");
$query_row=mysql_fetch_array($query);
echo($query_row[pass]);

NogDog
10-20-2005, 01:44 PM
As tirebiter alludes to, mysql_query() returns a resource ID which it uses internally to point to the query results. You then need to use one of the mysql_fetch_*() functions to access those results. See http://www.php.net/mysql_query , particularly Example 2, for an illustration of this process.

Smiley82
09-27-2007, 02:01 PM
Hi: I am also having problems. I am getting the Resource id#3 when I add in this code:

include("conn.php");
$sql = "select * from Client";
$result = connect($sql);

print ($result);

what do you suggest?

NogDog
09-28-2007, 05:02 AM
I suggest the exact same thing I suggested in my previous reply in this thread.

xthematrix
03-15-2008, 10:21 PM
I am getting Resource id #3 when i try to display the result of a field in the database. Below is my code

$query = "SELECT groupnum FROM users WHERE username='$username'";
$result = mysql_query($query);
echo $result;

When I use the mysql_fetch_array as shown below, nothing appears at all. Instead it shows up as a blank line. Any suggestions?

$query = "SELECT groupnum FROM users WHERE username='$username'";
$result = mysql_query($query);
$query_row=mysql_fetch_array($result);
echo $query_row;

skywalker2208
03-15-2008, 10:36 PM
I am getting Resource id #3 when i try to display the result of a field in the database. Below is my code

$query = "SELECT groupnum FROM users WHERE username='$username'";
$result = mysql_query($query);
echo $result;

When I use the mysql_fetch_array as shown below, nothing appears at all. Instead it shows up as a blank line. Any suggestions?

$query = "SELECT groupnum FROM users WHERE username='$username'";
$result = mysql_query($query);
$query_row=mysql_fetch_array($result);
echo $query_row;
I think the problem you are having is you have single quotes around the user name variable and that states it as a string. So it is looking for $username in the database and not the actual username you are looking for.

NogDog
03-16-2008, 03:57 AM
Never assume things work:

$query = "SELECT groupnum FROM users WHERE username='$username'";
$result = mysql_query($query);
if($result == false)
{
user_error("Query failed: " . mysql_error() . "<br />\n$query");
}
elseif(mysql_num_rows($result) == 0)
{
echo "<p>Sorry, no rows were returned by your query.</p>\n";
}
else
{
while($query_row = mysql_fetch_assoc($result))
{
foreach($query_row as $key => $value)
{
echo "$key: $value<br />\n";
}
echo "<br />\n";
}
}