Jump to content

Trouble doing UPDATE SET for editing photos ...


spacepoet

Recommended Posts

Hello:

 

I am trying to figure out how to do an UPDATE SET for a photo gallery based on the "photo_id" ... not working to well ...

 

Currently, it just uploads a photo but updates everything.

 

This is the code:

Photo_Edit.php

<?php

$photo_id = $_REQUEST['photo_id'];

?>

...


<?php


$query=mysql_query("SELECT * FROM gallery_photos WHERE photo_id = $photo_id") or die("Could not get data from db: ".mysql_error());

while($result=mysql_fetch_array($query))
{
  $photo_id=$result['photo_id'];
  $photo_filename=$result['photo_filename'];
  $photo_caption=$result['photo_caption'];
}

?>

<form enctype="multipart/form-data" action="a_Photo_Upload2.php" method="post" name="upload_form">

<input type='hidden' name='photo_id' value='<?php echo $photo_id; ?>' />


<table width='600' border='0' id='tablepadding' align='center'>


<tr>
<td width='50'>
  Photo:
<td width='550'>     
    <input name='photo_filename[]' id='my_photo' type='file' />
    <div style='clear: both;'></div>
    Current photo:
    <div style='clear: both;'></div>
    <img src="../gallery/tb_<?php echo $photo_filename; ?>" width="100px" class='imgCenter' />
    <div style='clear: both;'></div>
    <a href="javascript:void(0);" onmouseover="tooltip.show('<img src=../gallery/tb_<?php echo $photo_filename; ?> width=500 />');" onmouseout="tooltip.hide();">Larger view</a>
</td>
</tr>

<tr>
<td>
     Description:
</td>
<td>
    <textarea name='photo_caption[]' cols='100' rows='10'><?php echo $photo_caption; ?></textarea>
</td>
</tr>

<tr>
<td>
        <input type='submit' name='submit' value='Edit Product' />
</td>
</tr>
</table>
</form>

 

Goes to this page, where I am having the problems:

 

a_Photo_Upload2.php

<?php echo $photo_id; ?>

<?php
// initialization
$result_final = "";
$counter = 0;

// List of our known photo types
$known_photo_types = array( 
					'image/pjpeg' => 'jpg',
					'image/jpeg' => 'jpg',
					'image/gif' => 'gif',
					'image/bmp' => 'bmp',
					'image/x-png' => 'png'
				);

// GD Function List
$gd_function_suffix = array( 
					'image/pjpeg' => 'JPEG',
					'image/jpeg' => 'JPEG',
					'image/gif' => 'GIF',
					'image/bmp' => 'WBMP',
					'image/x-png' => 'PNG'
				);

// Fetch the photo array sent by preupload.php
$photos_uploaded = $_FILES['photo_filename'];

// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];

while( $counter <= count($photos_uploaded) )
{
	if($photos_uploaded['size'][$counter] > 0)
	{
		if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
		{
			$result_final .= "File ".($counter+1)." is not a photo<br />";
		}

		else
		{

			$new_id = mysql_insert_id();
			$filetype = $photos_uploaded['type'][$counter];
			$extention = $known_photo_types[$filetype];
			$filename = $new_id.".".$extention;

			mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

			// Store the orignal file
			copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$filename);

			// Let's get the Thumbnail size
			$size = GetImageSize( $images_dir."/".$filename );
			if($size[0] > $size[1])


			//{
				//$thumbnail_width = 100;
				//$thumbnail_height = (int)(100 * $size[1] / $size[0]);
			//}
			//else
			//{
				//$thumbnail_width = (int)(100 * $size[0] / $size[1]);
				//$thumbnail_height = 100;
			//}



			{
				//$thumbnail_width = 690;
				//$thumbnail_height = (int)(500 * $size[1] / $size[0]);



				$old_width = $size[0];
				$old_height = $size[1];

				$thumbnail_width = 690;
				$thumbnail_height = ($old_height * $thumbnail_width / $old_width);					





			}
			else
			{
				$thumbnail_width = (int)(690 * $size[0] / $size[1]);
				$thumbnail_height = 500;
			}



			// Build Thumbnail with GD 1.x.x, you can use the other described methods too
			$function_suffix = $gd_function_suffix[$filetype];
			$function_to_read = "ImageCreateFrom".$function_suffix;
			$function_to_write = "Image".$function_suffix;

			// Read the source file
			$source_handle = $function_to_read ( $images_dir."/".$filename ); 

			if($source_handle)
			{
				// Let's create an blank image for the thumbnail
			     	//$destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height );
			     	
			    $destination_handle = imagecreatetruecolor( $thumbnail_width, $thumbnail_height ); 	
			     	
			     	

				// Now we resize it

		      	ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $size[0], $size[1] );


			}

			// Let's save the thumbnail
			$function_to_write( $destination_handle, $images_dir."/tb_".$filename );
			ImageDestroy($destination_handle );
			//

			$result_final .= "<img src='".$images_dir. "/tb_".$filename."' style='margin-right: 20px; width: 100px;' />";


		}
	}
$counter++;
}

// Print Result
echo <<<__HTML_END

$result_final

__HTML_END;
?>

 

 

Can anyone show me how to make this work, OR show me a way to do this ...

 

Thank you.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.