Jump to content

complete code to display picture w\variable initialized in image.php


Recommended Posts

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 image.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]

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.