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
Share on other sites

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.

Link to comment
Share on other sites

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>";



} 

 

 

 

Link to comment
Share on other sites

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();} 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();
}

?>

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.