Jump to content

Resource id #35 error?


otester

Recommended Posts

I am currently trying create a sales system where it checks the user's username against the database to check whether they are in the list of buyers.

 

The mysql query returns "Resource id #35", I need it to return the actual username (which I manually inserted into the database to test).

 

 

PHP code that fetches from database:

 

<?php
$con = mysql_connect("x","x","x");
	if (!$con)
  		{
  		die('Could not connect: ' . mysql_error());
  		}

mysql_select_db("x", $con);

$check_buyer = "SELECT * FROM Buyers WHERE Buyer='x'";

        $buyer = mysql_query($check_buyer);
?>

 

 

Product page:

 

<?php
		include("/home/x/public_html/scripts/buyer.php");

		if ($user->data['user_id'] == ANONYMOUS)
		{
			echo 'To use ' . $product . 'you must be logged in!';
   				echo '<br /><a href="http://x/forum/ucp.php?mode=register">Register</a>';
			echo ' or ';
    			echo '<a href="http://x/forum/ucp.php?mode=login">Sign In</a>';
		}

		elseif ($user->data['username_clean'] == $buyer)
		{
			echo "<h3>Welcome to x</h3>";
		}

		else
		{
   				echo "You need to buy this product to use it!";

			echo $user->data['username_clean']; //test whether username is outputted correctly - which it did
			echo $buyer; //Fetched from mysql - returned "Resource id #35", not the desired username
		}
?>

 

 

Any help would be great!

 

 

Thanks,

 

otester

Link to comment
https://forums.phpfreaks.com/topic/209837-resource-id-35-error/
Share on other sites

It gives that error because $buyer is still a mysql resource.

You still need to fetch the values from the resource like this.

 

<?php

$con = mysql_connect("x","x","x");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("x", $con);

$check_buyer = "SELECT * FROM Buyers WHERE Buyer='x'";
$buyer = mysql_query($check_buyer);

if(mysql_num_rows($buyer))
{
	$row = mysql_fetch_array($buyer);
	$buyer = $row['username']; //Change username to the correct field name in your database
}
else
{
	$buyer = '';
}
?>

It gives that error because $buyer is still a mysql resource.

You still need to fetch the values from the resource like this.

 

<?php

$con = mysql_connect("x","x","x");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("x", $con);

$check_buyer = "SELECT * FROM Buyers WHERE Buyer='x'";
$buyer = mysql_query($check_buyer);

if(mysql_num_rows($buyer))
{
	$row = mysql_fetch_array($buyer);
	$buyer = $row['username']; //Change username to the correct field name in your database
}
else
{
	$buyer = '';
}
?>

 

Worked perfectly, thanks for your help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.