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
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 = '';
}
?>

Link to comment
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 = '';
}
?>

 

Worked perfectly, thanks for your help!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.