Jump to content

Resource id #2 (Old Error?)


justlukeyou

Recommended Posts

Hi,

 

I have the following code which I have been able to put together with alot of the brilliant help on this forum.  When I run this code it just came up with a blank screen and the CSS however I added another error print "echo "fetchdata: $fetchdata<br>Failed with error: " . mysql_error()  . '<br>';" and the result now is "fetchdata: Resource id #2".

 

However, when search for this on Google many of the responses data back from between 2002-2006.  Does it just mean that there is an error with the second if query or does  Resource id #2 refer to a specific error? Im really puzzled why I cant find anything more modern to this error on Google.

 

<?php
if( isset($_GET['id']) && ctype_digit($_GET['id']) ) { // validate that $_GET['id'] is set, and contains only numeric characters
$id = (int) $_GET['id']; // cast value as an integer, and assign to $id
$query = "SELECT * FROM productfeed WHERE id = $id";
if( !$fetchdata = mysql_query($query) ) { // numeric values shouldn't be quoted in query strings.
echo "query: $query<br>Failed with error: " . mysql_error()  . '<br>';
} else {
while($row = mysql_fetch_array($fetchdata))

$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];




echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>&#163; $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>";

echo "fetchdata: $fetchdata<br>Failed with error: " . mysql_error()  . '<br>';

}
} else {
echo 'Product is not available.  Please visit our <a href="http://www.ukhomefurniture.co.uk">Homepage</a>';
exit();
} 

?>

Link to comment
https://forums.phpfreaks.com/topic/227662-resource-id-2-old-error/
Share on other sites

i would remove this: if( !$fetchdata = mysql_query($query) )

 

and replace it with this:

 

$query = "SELECT * FROM productfeed WHERE id = $id";
$fetchdata = mysql_query($query) or die("query: $query<br>Failed with error: " . mysql_error()  . '<br>');
if (!$fetchdata) 

 

A SELECT query that executes without error returns a result resource.

 

Why on earth are you echoing "fetchdata: $fetchdata<br>Failed with error: " . mysql_error()  . '<br>' INSIDE the while() loop that will only be executed when the query executed without error and there is at least one row in the result set.

hi BlueSky,

 

I tried your code however it comes up with error: "Failed with error" which relates the first echo.

 

It also kicked out the else loop I had at the end which gives a message if the id is not in the database.    Is there a standard method of doing _GET?

 

<?php
if( isset($_GET['id']) && ctype_digit($_GET['id']) ) { // validate that $_GET['id'] is set, and contains only numeric characters
$id = (int) $_GET['id']; // cast value as an integer, and assign to $id
$query = "SELECT * FROM productfeed WHERE id = $id";$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error()  . '<br>');if (!$fetchdata);
echo "query: $query<br>Failed with error: " . mysql_error()  . '<br>';
} else {
while($row = mysql_fetch_array($fetchdata))

$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];




echo "<div class=\"productdisplayshell\"> <div class=\"productdisplayoutline\"> <div class=\"productborder\"><center> <a href=\"$link\" target=\"_blank\" ><img src=\"$image\" /></a> </center> </div></div> <div class=\"productdescriptionoutline\"><div class=\"productdescriptionbox\"> <a href=\"$link\" target=\"_blank\" >$description</a> </div><div class=\"productfulldescriptionbox\"> $fulldescription </div></div> <div class=\"productpriceoutline\"> <div class=\"productpricebox\"><center>&#163; $price</center></div> <div class=\"productbuybutton\"><center><a href=\"$link\" target=\"_blank\" ><img src=/images/buybutton.png /></a></center></div></div></div>";



} 

 

 

 

Hi,

 

It turned this into an error.  But Im really struggling with getting the data to appear.  It appears without the $_GET['id'.  I'm finding it like spinning plates but the help on this forum is a massive help.

 

else {echo 'Product is not available.  Please visit our <a href="http://www..co.uk">Homepage</a>';exit();} 

Your code would be much easier to debug if you didn't put multiple statements on one line. I cleaned it up and made some changes. Try this and see if you get further:

<?php
if( isset($_GET['id']) && ctype_digit($_GET['id']) ) { // validate that $_GET['id'] is set, and contains only numeric characters
$id = (int) $_GET['id']; // cast value as an integer, and assign to $id
$query = "SELECT * FROM productfeed WHERE id = $id";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error()  . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
	$id = $row['id'];
	$image = $row['awImage'];
	$link = $row['link'];
	$description = $row['description'];
	$fulldescription = $row['fulldescription'];
	$price = $row['price'];
	echo "<div class='productdisplayshell'>
	<div class='productdisplayoutline'>
	<div class='productborder'><center>
	<a href='$link' target='_blank'><img src='$image'/></a>
	</center> </div></div>
	<div class='productdescriptionoutline'>
	<div class='productdescriptionbox'>
	<a href='$link' target='_blank' >$description</a>
	</div>
	<div class='productfulldescriptionbox'>$fulldescription</div>
	</div>
	<div class='productpriceoutline'>
	<div class='productpricebox'>
	<center>&#163; $price</center>
	</div>
	<div class='productbuybutton'>
	<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
	</div>
	</div>
	</div>";
} else {
	echo "Incoming ID is invalid: {$_GET['id']}<br />";
}
?>

 

Ken

Hi, brilliant thanks for your help.  With the code it came up an $end error so I removed the invalid part line and then add another curly so it just presented the product but if I searched for an ID not in my database it did not give a message.  So I added a previous an echo message however this shows permanently.  So it shows the product and then below it says that there are now ids available within the database.  Hopefully I can get the not available line to work and then I should be there.

 

This forum is great.

 

<?php
if( isset($_GET['id']) && ctype_digit($_GET['id']) ) { // validate that $_GET['id'] is set, and contains only numeric characters
$id = (int) $_GET['id']; // cast value as an integer, and assign to $id
$query = "SELECT * FROM productfeed WHERE id = $id";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];
echo "<div class='productdisplayshell'>
<div class='productdisplayoutline'>
<div class='productborder'><center>
<a href='$link' target='_blank'><img src='$image'/></a>
</center> </div></div>
<div class='productdescriptionoutline'>
<div class='productdescriptionbox'>
<a href='$link' target='_blank' >$description</a>
</div>
<div class='productfulldescriptionbox'>$fulldescription</div>
</div>
<div class='productpriceoutline'>
<div class='productpricebox'>
<center>&#38;#163; $price</center>
</div>
<div class='productbuybutton'>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</div>
</div>
</div>";
} 
echo 'Product is not available.  Please visit our <a href="http://www.domain.co.uk">Homepage</a>';exit();
}

?>

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.