Jump to content

[almost done] retrieving image from database and displaying it


ra2833

Recommended Posts

well,

 

i have narrowed down my error to one variable in my code;

 

callimagetodsiplay.php (this code works perfectly fine)

<?php
echo $output ="<img src="retreiveimage.php?image_unique_id_s=94">";
?>

 

 

retreiveimage.php

<?php
$image_unique_id_rr = intval($_GET['image_unique_id_s']);   //if i was to initialize my variable here instead of on the calling page, it "too" works here;


mysql_select_db($database_faqSQLconn, $faqSQLconn);
$query = "SELECT * FROM faq_image WHERE faq_image.image_unique_id  = '".$image_unique_id_rr."'";
$faq_image_result = mysql_query($query, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query);
$row = mysql_fetch_array($faq_image_result);

header("Content-type: %s", $row['name']['type']);

$im = imagecreatefromstring($row['image']);
imagegif($im);
imagedestroy($im);
?>

 

BUT MY HEADACHE IS HERE..... awwww .... when i want to send a variable instead of an number my code does not display the image awwww..

 

callimagetodsiplay.php

<?php
$faq_unique_id_r = intval($_GET['faq_unique_id_s']);    //i have echo this and the correct number does come up
?>
.
.
.
<html>
<?php
echo $output ="<img src="image.php?image_unique_id_s='.$faq_unique_id_r.'" >";
?>

is it my syntax on ('.$faq_unique_id_r.') this small little section that will not evaluate???????, but when i do an echo on retreiveimage.php the number shows up???

 

what gives????

 

Link to comment
Share on other sites

Believe it or not, when i initialize my variable in "any" of my pages to a number (interger) i do get my image displayed on my final page.

 

from index.php --> callimagetodsiplay.php --> retreiveimage.php

 

if i initialize my variable ($blah=94) at index.php, and assign $blah to be received by callimagetodsiplay.php "and" retreiveimage.php my image is displayed

 

if i initialize my variable ($blah=94) at callimagetodsiplay.php, and assign $blah to be received by retreiveimage.php my image is displayed

 

this is what i have learned about single quotes vs. double quotes, but i am not quite sure about html tags, any all help that i have received is greatly appreciated.

 

the idea is to have a certain link to be clicked by the user, and that perticular link will call from the database a perticular image.

 

single quotes are upto 50% faster and do not get interpolated

double quotes do get interpolated, which means that they evalutate the value of a php variable

double quotes are required when you use the escape key like \n (newline)

 

example 1

the value of this variable ($blue) will be copied into this new variable ($emc)

$blue = 4;

$emc = "$blue";

 

display will be 4;

 

example 2

the string ($blue) will be copied into this new variable ($emc)

$blue = 4;

$emc = '$blue';

 

display will be $blue

 

 

 

<?php

$string1 = 'This string will not be interpolated\n<br />';
$string2 = 'Part of this string will be interpolated ' . "\n" . '<br />';
$string3 = "$string2";
$string4 = '$string1<br />';
$string5 = "This will be interpolated\n<br />";

echo $string1 . $string2 . $string3 . $string4 . $string5;

?>

 

 

so i still need help in typing the correct syntax in which my stuipid variable will be evalutated to where i can display the image.........

Link to comment
Share on other sites

remember guys, i want to send a variable instead of an initial number. see image.php to understand what i mean.  more info: depending on what the user will click, it will send a number to a variable, then that variable will travel through the entire site, and when i need the image to be displayed, then it is displayed.

 

as it stands now, i would have to hard code "one" number and have th same picture come up all the time.

 

index.php

<?php require_once('Connections/faqSQLconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
		$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
		$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

		switch ($theType) {
			case "text":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;    
			case "long":
			case "int":
				$theValue = ($theValue != "") ? intval($theValue) : "NULL";
			break;
			case "double":
				$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
			break;
			case "date":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;
			case "defined":
				$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
			break;
		}

	return $theValue;
	}
}

mysql_select_db($database_faqSQLconn, $faqSQLconn);
$query_faq_all = "SELECT * FROM faq WHERE faq.faq_unique_id";
$query_limit_faq_all = sprintf("%s LIMIT %d, %d", $query_faq_all, $startRow_faq_all, $maxRows_faq_all);
$faq_all = mysql_query($query_limit_faq_all, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query_limit_faq_all);
$row_faq_all = mysql_fetch_assoc($faq_all);

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {
	$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && ($_FILES['uploadfilefield']['size'])) {
	if ($_POST['MAX_FILE_SIZE'] >= $_FILES['uploadfilefield']['size']) {
		$photo = addslashes(fread(fopen($_FILES['uploadfilefield']['tmp_name'], "rb"), $_FILES['uploadfilefield']['size']));
		$query = sprintf("INSERT INTO faq_image(image, file_type, faq_unique_id, name) VALUES ('%s', '%s', '%s', '%s')", $photo, $_FILES['uploadfilefield']['type'], $_POST['image_id'], $_FILES['uploadfilefield']['tmp_name']);

		mysql_select_db($database_faqSQLconn, $faqSQLconn);
		$faq_image_result = mysql_query($query, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query);

		if ($faq_image_result) {
			$messages[] = "Your file is successfully stored in database";

		}

		else {
			$messages[] = mysql_error();
		}
	}

	else {
		$messages[] = "The file is bigger than the allowed size (96k) please reduce your file size";
	}
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>

	<form id="form1" name="form1" method="POST" enctype="multipart/form-data" action="<?php echo $editFormAction; ?>">
		<?php
			if (isset($messages)) {
				foreach ($messages as $message) {
					print $message ."<br>";
				}
			}
		?>

		<input type="hidden" name="image_id" value="<? echo $row_faq_all['faq_unique_id']  + 1 ?>"/>

		<input type="file" name="uploadfilefield" />

		<input type="hidden" name="MAX_FILE_SIZE" value="9600000" />

		<input type="submit" name="Submit" value="Submit" />

		<input type="hidden" name="MM_insert" value="form1" />

	</form>
</body>
</html>

<?php
mysql_free_result($faq_all);
?>

 

issue.results.php

<?php require_once('Connections/faqSQLconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
		$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
		$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

		switch ($theType) {
			case "text":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;    
			case "long":
			case "int":
				$theValue = ($theValue != "") ? intval($theValue) : "NULL";
			break;
			case "double":
				$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
			break;
			case "date":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;
			case "defined":
				$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
			break;
		}

	return $theValue;
	}
}

$faq_unique_id_r = intval($_GET['faq_unique_id_s']);

mysql_select_db($database_faqSQLconn, $faqSQLconn);
$query_faq_solution = "SELECT * FROM faq WHERE faq.faq_unique_id = '".$faq_unique_id_r."'";
$faq_solution = mysql_query($query_faq_solution, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query_faq_solution);
$row_faq_solution = mysql_fetch_assoc($faq_solution);
$totalRows_faq_solution = mysql_num_rows($faq_solution);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<meta http-equiv="Content-Type" content="image/gif; charset=iso-8859-1">
	<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<?php 
echo '<img '.$row['image'].' src="image.php?faq_unique_id_s='.$_GET['faq_unique_id'].'">';
?>
</body>
</html>
<?php
mysql_free_result($faq_solution);
?>

 

image.php

<?php require_once('Connections/faqSQLconn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
	function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
		$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;		
		$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

		switch ($theType) {
			case "text":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;    
			case "long":
			case "int":
				$theValue = ($theValue != "") ? intval($theValue) : "NULL";
			break;
			case "double":
				$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
			break;
			case "date":
				$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
			break;
			case "defined":
				$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
			break;
		}

	return $theValue;
	}
}

$image_unique_id_rr = 130;

mysql_select_db($database_faqSQLconn, $faqSQLconn);
$query = "SELECT * FROM faq_image WHERE faq_image.image_unique_id  = '".$image_unique_id_rr."'";
$faq_image_result = mysql_query($query, $faqSQLconn) or die("Query failed: " . mysql_error() . " Actual query: " . $query);
$row = mysql_fetch_array($faq_image_result);

header("Content-type: %s", $row['name']['type']);

$im = imagecreatefromstring($row['image']);
imagegif($im);
imagedestroy($im);
?>

 

i have attached the faq_for_6_1 database, you will have to rename them to .sql instead of .txt unless you do copy/paste of the content into mysql.

i have verified that you can:
1. insert an image with index.php
2. you can the simply browse to issue.results.php

3. before you can see the picture you have to match what your database has for the unique id, and then place that number in issue.results.php to see the picture

 

so i have tried quite a few suggestions, but i have yet be able to use the code with this line in my image.php file:

$faq_unique_id_r = intval($_GET['faq_unique_id_s']);

 

[attachment deleted by admin]

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.