Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resource id #4 Error on Binary Row

Status
Not open for further replies.

Kriekie

Technical User
Nov 21, 2004
10
ZA
Hi

I'm trying to access an image from a binary blob row in mySQL, but keep getting the error "Resource id #4"

The code I'm using:

<?php
@require("scripts/connect.php");
$iid = $_REQUEST[iid];
$Query = mysql_query("Select image from image where image_id = $iid");
header("Content-type: image/jpeg");
$result = mysql_fetch_array($Query);
$image = $result["image"];
echo $image;
?>

Thanks for any help.
 
You've missed a step. Before you can use mysql_fetch_array(), you have to invoke mysql_query().

Mysql_query(), when used with a successful SELECt query, will return a result handle that your code will pass to mysql_fetch_array().

See the PHP online manual entry for mysql_fetch_array() for example code.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Also, I don't know the content of the connect.php file your script includes. Does it select the correct database within your MySQL server?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Also, a tip:
When writing a query, it the mysql functions should be in uppercase, fieldnames, etc. should be in lowercase.

SELECT ... FROM ... WHERE ... = ...

Code:
// Quote variable to make safe
function quote_smart($value)
{
   // Stripslashes
   if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
   }
   // Quote if not integer
   if (!is_numeric($value)) {
       $value = "'" . mysql_real_escape_string($value) . "'";
   }
   return $value;
}

// Connect
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
   OR die(mysql_error());

// Make a safe query
$query = sprintf("SELECT `image` FROM `image` WHERE `image_id` = '%s'",
           quote_smart($_POST['username']));

mysql_query($query);

That query is also improved, regarding sql injection

ref.:
Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top