I suppose PHP5's mysqli functions are not as easy to use as it's older versions. I get this error message:
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\showimage.php on line 17
Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\showimage.php on line 27
the script's code is:
<?php
// showimage.php -- sends a pic to the db from the /uploads folder
// instalize the config file.
$notemplate = TRUE; // do not use a template fror this page
require('includes/config.php');
// check to see if the id is valid
if(is_numeric($_GET['pid'])) {
// get the pic from the db
require(MYSQL_PATH);
$query = "SELECCT * FROM uploaded_pics WHERE id='{$_GET['pid']}' AND
approved = 'Y'";
if($r = mysqli_query($dbc, $query)) {
header("content-type: image/jpeg");
$row = mysqli_fetch_array($r);
echo file_get_contents(FILE_BASE."/uploads/{$row['file_name']}");
exit(); // kill the script.
} else {
// query failed
die(mysqli_error($dbc));
}
} else { // id isn't valid
echo "the ID is not valid";
}
?>
This is the database script:
<?php
// MySQL connectivity
$dbc = @mysqli_connect('localhost', 'username', 'password', 'metrorailroad');
function escape_data($data) { // function for escaping data
global $dbc; // need the connection to the db.
if(ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysqli_real_escape_string($data, $dbc);
}
?>