[SOLVED] Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Images

Post by Stelios »

Can anyone tell me whether you can test scripts locally that involve dynamic display of images? I am trying to display a page where i am supossed to retrieve an image from my db and I cant get the image to be displayed...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes you can. Maybe you should post your code. Use

Code: Select all

and

Code: Select all

correctly now
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

Here is my code:

Code: Select all

<html>
<head>
<title>e-Music Image Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<?php 
// This page displays the details for a particular print.

if (is_numeric ($HTTP_POST_GET['pid'])) { // Make sure there's a print ID.

@ $db= mysql_pconnect('localhost','root','password');

if (!$db)
{
	echo 'Error:Could not connect to the database. Please try again later';
	exit;
}

mysql_select_db('emusic');


	$query = "SELECT * FROM songs, images WHERE songs.song_id = images.song_id AND images.image_id = {$HTTP_POST_GET['pid']}";
	$result = mysql_query ($query);
	$row = mysql_fetch_array ($result, MYSQL_ASSOC);
	

	// Display a header.
	echo "<div align="center">
<b>{$row['image_name']}</b>
</div>";

	// Get the image information and display the image.
	if ($image = @getimagesize ("C:\Program Files\Apache Group\Apache\htdocs/{$row['image_name']}")) 
	{
		echo "<div align="center"><img src="C:\Program Files\Apache Group\Apache\htdocs/{$row['image_name']}" $image[3] alt="{$row['image_name']}" />";	
	} 
	else 
	{
		echo "<div align="center">No image available."; 
	}
	echo '<br />' . stripslashes($row['description']) . '</div>';

	
}

?>
</body>
</html>
feyd | flipped

Code: Select all

to

Code: Select all

. [/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where's $HTTP_POST_GET coming from?

Your paths to the files may be a problem, think about using $_SERVER['DOCUMENT_ROOT'] instead.. however, the img tag's src attribute should not be the document root, it should be the reference to the url path needed to get to the image.
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

it is coming from here:

Code: Select all

<?php
<html>
<head>
<title>e-Music Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="center"><strong><font color="#FF0000" size="7">e - Music</font></strong></div>

<?php



//create short variable names
$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm=trim($searchterm);

if (!$searchtype || !$searchterm)
{
	echo 'You have not entered search details. Please go back and try again.';
	exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

@ $db= mysql_pconnect('localhost','root','password');

if (!$db)
{
	echo 'Error:Could not connect to the database. Please try again later';
	exit;
}

mysql_select_db('emusic');

$query = "select * from songs,images where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="20%"><b>Title</b></td>
<td align="left" width="20%"><b>Group Name</b></td>
<td align="centre" width="20%"><b>Type of Music</b></td>
<td align="center" width="20%"><b>Review</b></td>
<td align="right" width="20%"><b>Image</b></td>
</tr>';

echo '<p>Number of songs found: '.$num_results.'</p>';


while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

	// Display each record.
	echo "	<tr>
		<td align="left"><a href="results.php?aid={$row['song_id']}">{$row['title']}</a></td>
		<td align="left">" . stripslashes($row['group_name']) . "</td>
		<td align="left">" . stripslashes($row['type']) . "</td>
		<td align="center">{$row['review']}</td>
		<td align="right"><a href="view_image.php?pid={$row['image_id']}">{$row['image_name']}</td>
	</tr>\n";
	
} // End of while loop.
echo '</table>'


?>
</body>
</html>


?>
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

what i've done is that i have created my db and then stored in the field image_name the name of a picture which I have stored in htdocs. I am searching for the song I find the song which has a link, that is supposed to open a new page called <i>http://localhost/view_image.php?pid=1</i> and display the picture. The page is opening but I dont get anything at all!!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

so the first code you posted was view_image.php? $HTTP_POST_GET doesn't exist. I think you mean $HTTP_GET_VARS
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

found it!!!! thnx for your help!!! ur great!
Post Reply