$id variable/record passed to new page, BUT...
Moderator: General Moderators
- gregorious
- Forum Commoner
- Posts: 34
- Joined: Wed Aug 23, 2006 9:55 am
- Location: Orlando, FL
$id variable/record passed to new page, BUT...
I am building a CMS for real estate company and almost done, except for:
The CMS presents a list of properties of existing record for editing; the ADMIN SELECTS a property (the $id [variable/record] is passed to the EDIT page). The EDIT page allows editing of the property, but also provides a link to ADD A PHOTO to the property, the ADMIN clicks on the link (the $id [variable/record] is passed to the ADD PHOTO page). At the top of the ADD PHOTO page there is a PHP/MYSQL "$select=mysql_query", it handles the $id [variable/record] and gets the property data and displays some brief info on the property to acknowledge the property being EDITED. Great!
On the same page, just below the above, I start my UPLOAD / FILENAME / IMAGECOPYRESAMPLED / SAVE code <-- here is the hitch, this area of page code does not remember the $id [variable/record] that was passed to it from the previous pages. I could use the record$id in the image FILENAME and else where; but the $id is lost to this second body of code.
The UPLOAD / FILENAME / IMAGECOPYRESAMPLED / SAVE code starts --> if (isset($_POST['uploadimage'])){ ...yada yada... and goes to }else{ , the $id [variable/record] works again, so what am I missing?
Thanks in advance,
Greg
The CMS presents a list of properties of existing record for editing; the ADMIN SELECTS a property (the $id [variable/record] is passed to the EDIT page). The EDIT page allows editing of the property, but also provides a link to ADD A PHOTO to the property, the ADMIN clicks on the link (the $id [variable/record] is passed to the ADD PHOTO page). At the top of the ADD PHOTO page there is a PHP/MYSQL "$select=mysql_query", it handles the $id [variable/record] and gets the property data and displays some brief info on the property to acknowledge the property being EDITED. Great!
On the same page, just below the above, I start my UPLOAD / FILENAME / IMAGECOPYRESAMPLED / SAVE code <-- here is the hitch, this area of page code does not remember the $id [variable/record] that was passed to it from the previous pages. I could use the record$id in the image FILENAME and else where; but the $id is lost to this second body of code.
The UPLOAD / FILENAME / IMAGECOPYRESAMPLED / SAVE code starts --> if (isset($_POST['uploadimage'])){ ...yada yada... and goes to }else{ , the $id [variable/record] works again, so what am I missing?
Thanks in advance,
Greg
- gregorious
- Forum Commoner
- Posts: 34
- Joined: Wed Aug 23, 2006 9:55 am
- Location: Orlando, FL
Page code below.
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Page code below.Code: Select all
<?php @require_once('../includes/connect.php'); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Real Estate Professionals</title>
<link href="res.css" rel="stylesheet" type="text/css">
</head>
<body>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="center"><table width="760" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="100" bgcolor="#00833D"> </td>
<td width="500" background="../images/bkgd_ltgray50x2000.jpg">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"><span class="listing01"> <span class="body01"><strong><br>
</strong></span></span><span class="head01">UPLOAD RESIDENTIAL PICTURE</span>
<span class="listing01"><span class="body01"><strong><br>
</strong></span>< back to <a href="admin.php">admin</a> -
exit to <a href="../index.htm">website</a> ><br>
</span><br>
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10"> </div>
</p></td>
</tr>
</table>
</td>
<td width="100" bgcolor="#393989"> </td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="10">
<tr align="left" valign="bottom">
<td width="100" bgcolor="#00833D"> </td>
<td width="500">
<?php
$resselect = @mysql_query("SELECT
res_street01,
res_city,
res_state,
res_zip,
res_price,
res_status,
res_type
FROM residential WHERE res_id='$id'");
if (!$resselect) {
echo("Error SELECTING data from database!<br><br>" .
"<br> />Error: " . mysql_error() . "</p>");
exit();
}
while ($resarray = mysql_fetch_array($resselect)) {
$resstreet01 = htmlspecialchars($resarray["res_street01"]);
$rescity = htmlspecialchars($resarray["res_city"]);
$resstate = htmlspecialchars($resarray["res_state"]);
$reszip = htmlspecialchars($resarray["res_zip"]);
$resstatus = htmlspecialchars($resarray["res_status"]);
$resprice = htmlspecialchars($resarray["res_price"]);
$restype = htmlspecialchars($resarray["res_type"]);
}
$imgselect = @mysql_query("SELECT
image_tmb_name,
image_tmb_path,
image_tmb_width,
image_tmb_height
FROM image WHERE image_res_id='$id'");
if (!$imgselect) {
echo("Error SELECTING data from database!<br><br>" .
"<br> />Error: " . mysql_error() . "</p>");
exit();
}
while ($resarray2 = mysql_fetch_array($imgselect)) {
$imagetmbname = htmlspecialchars($imgarray["image_tmb_name"]);
$imagetmbpath = htmlspecialchars($imgarray["image_tmb_path"]);
$imagetmbwidth = htmlspecialchars($imgarray["image_tmb_width"]);
$imagetmbheight = htmlspecialchars($imgarray["image_tmb_height"]);
}
?>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="250" align="right" valign="top">
<table width="220" border="0" align="right" cellpadding="0" cellspacing="10">
<tr>
<td align="left" valign="top"><hr align="left" width="180" size="1" noshade>
<span class="caption_cap">Record Id <?php echo $id; ?></span><br>
<span class="listing01"><strong><?php echo $restype ;?></strong><br>
<?php echo $resstreet01 ;?><br>
<?php echo $rescity ;?>
<?php echo $resstate ;?> <?php echo $reszip ;?><br>
<br>
<?php echo $resstatus ;?><br>
<?php echo $resprice ;?></span>
<hr align="left" width="180" size="1" noshade>
<br><span class="listing01">Use the <b>BROWSE</b> button below to select an
PICTURE to be uploaded to your website.<br>
<br>
Only <b>JPG</b>, <b>GIF</b>, and <b>PNG</b>
PICTURES under 1.7 MB in file size can be uploaded.</span><br>
</td>
</tr>
</table>
</td>
<td width="250" align="left" valign="top">
<table width="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="125" align="left" valign="top"><span class="caption_cap">PICTURE 01<br>
<img src="../images/arrow-down.gif" width="9" height="9">
<span class="listing01">[<strong>DELETE</strong>]</span><br>
</span></td>
<td width="125" align="left" valign="top"><span class="caption_cap">PICTURE 02<br>
</span></td>
</tr>
<tr>
<td align="left" valign="top"><img src="../<?php echo $imagetmbpath ;?><?php echo $imagetmbname ;?>"
width="<?php echo $imagetmbwidth ;?>" height="<?php echo $imagetmbheight ;?>" border="1"><br></td>
<td align="left" valign="top"><img src="../images/tmb-spacer-gry90.jpg" width="90" height="90" border="1"></td>
</tr>
<tr>
<td align="left" valign="middle"> </td>
<td align="left" valign="middle"> </td>
</tr>
<tr>
<td align="left" valign="top"><span class="caption_cap">PICTURE 03<br>
<br>
</span></td>
<td align="left" valign="top"><span class="caption_cap">PICTURE 04<br>
</span></td>
</tr>
<tr>
<td align="left" valign="top"><img src="../images/tmb-spacer-gry90.jpg" width="90" height="90" border="1"></td>
<td align="left" valign="top"><img src="../images/tmb-spacer-gry90.jpg" width="90" height="90" border="1"></td>
</tr>
</table>
</td>
</tr>
</table>
<blockquote>
<?php
//load the config file
include("../includes/images-config.php");
//if the for has submittedd
if (isset($_POST['uploadimage'])){
$file_type = $_FILES['imgfile']['type'];
$file_name = $_FILES['imgfile']['name'];
$file_size = $_FILES['imgfile']['size'];
$file_tmp = $_FILES['imgfile']['tmp_name'];
//check if you have selected a file.
if(!is_uploaded_file($file_tmp)){
echo "<br><br><span class='listing01'>Either the PICTURE you tried to upload <br>
exceeds the 1.7 megabyte size limit, <br><br>or <br><br>
you did not select an PICTURE to upload!
<br><br><br><a href=\"$_SERVER[PHP_SELF]\">back</a></span><br><br><br><br>";
exit(); //exit the script and don't do anything else.
}
//check file extension
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
echo "<br><br><br><span class='listing01'>You tried to submit a invalid file type; <br>
(only gif, jpg, png, and jpeg IMAGES are allowed).<br><br><br>
<a href=\"$_SERVER[PHP_SELF]\">back</a></span><br><br><br><br>";
exit(); //exit the script and don't do anything else.
}
//get the file extension.
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
//create a random file name
$rand_name = md5(time());
$rand_name = rand(0,999999999);
// RESIDENTIAL THUMBNAIL ------------------------------------------------------------
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$tmb_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/jpeg" || $file_type == "image/jpg"){
$tmb_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$tmb_new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$tmb_new_img = imagecreatefromgif($file_tmp);
}
//get the new width variable.
$tmbwidth = $img_residential_tmb_width;
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newtmbwidth = $tmbwidth;
$newtmbheight = $tmbwidth/$imgratio;
}else{
$newtmbheight = $tmbwidth;
$newtmbwidth = $tmbwidth*$imgratio;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$tmb_resized_img = imagecreatetruecolor($newtmbwidth,$newtmbheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
imagecopyResampled($tmb_resized_img, $tmb_new_img, 0, 0, 0, 0, $newtmbwidth, $newtmbheight, $width, $height);
// explode it to get the extention
$parts = explode(".", $rand_name);
$tmb_name = 'tmb-'.$parts[0].$parts[1];
//save image
ImageJpeg ($tmb_resized_img,"../$path_residential_tmbs/$tmb_name.$file_ext");
ImageDestroy ($tmb_resized_img);
ImageDestroy ($tmb_new_img);
}
// RESIDENTIAL IMAGE ------------------------------------------------------------
//keep image type
if($file_size){
if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){
$pic_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/jpeg" || $file_type == "image/jpg"){
$pic_new_img = imagecreatefromjpeg($file_tmp);
}elseif($file_type == "image/x-png" || $file_type == "image/png"){
$pic_new_img = imagecreatefrompng($file_tmp);
}elseif($file_type == "image/gif"){
$pic_new_img = imagecreatefromgif($file_tmp);
}
//get the new width variable.
$picwidth = $img_residential_pic_width;
//list width and height and keep height ratio.
list($width, $height) = getimagesize($file_tmp);
$imgratio=$width/$height;
if ($imgratio>1){
$newpicwidth = $picwidth;
$newpicheight = $picwidth/$imgratio;
}else{
$newpicheight = $picwidth;
$newpicwidth = $picwidth*$imgratio;
}
//function for resize image.
if (function_exists(imagecreatetruecolor)){
$pic_resized_img = imagecreatetruecolor($newpicwidth,$newpicheight);
}else{
die("Error: Please make sure you have GD library ver 2+");
}
imagecopyResampled($pic_resized_img, $pic_new_img, 0, 0, 0, 0, $newpicwidth, $newpicheight, $width, $height);
// explode it to get the extention
$parts = explode(".", $rand_name);
$pic_name = 'pic-'.$parts[0].$parts[1];
//save image
ImageJpeg ($pic_resized_img,"../$path_residential_pics/$pic_name.$file_ext");
ImageDestroy ($pic_resized_img);
ImageDestroy ($pic_new_img);
}
$sqlinsert = "INSERT INTO image SET
image_res_id='$id',
image_pic_name='$pic_name.$file_ext',
image_pic_path='$path_residential_pics',
image_pic_width='$newpicwidth',
image_pic_height='$newpicheight',
image_tmb_name='$tmb_name.$file_ext',
image_tmb_path='$path_residential_tmbs',
image_tmb_width='$newtmbwidth',
image_tmb_height='$newtmbheight'";
if (@!mysql_query($sqlinsert)) {
echo("<p>Error INSERTING data to database: " . mysql_error() . "</p>\n</body>\n</html>");
exit();
}
echo "<div align='center'><br><br><br>Residential IMAGE uploaded!</div><br><br><br>";
}else{
echo "<span class='listing01'>
Then click the <strong>SAVE</strong> button to send a PICTURE to your website
(the upload process may take a few minutes, pleaae wait).<br><br><br>";
echo "<script>
function view_img(img_name){
document[img_name].src = uploadimage.imgfile.value;
document[img_name].width = 150;
}
</script>
<form action='$_SERVER[PHP_SELF]' method='post'
name='uploadimage' enctype='multipart/form-data'>
<input name='id' type='hidden' value='$id' />
//edited to show source of error and correct value
// was <input name='id' type='hidden' value='<?php echo $id ?>' />
<input type='hidden' name='MAX_FILE_SIZE' value='1700000'>
<span class='caption_cap'>Select Picture:</span><br>
<input type='file' name='imgfile' size='45' class='body01'
onchange=\"javascript:view_img('img_vv');\"><br>
<br>
<div align='center'><input type='submit' name='uploadimage' value=' SAVE '>
<br><br><br>
<img src='' name='img_vv' width='0'></div>
</form>"; }
?>
</blockquote>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"> <span class="body01">
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10">
<img src="../images/spacer-grn.jpg" width="10" height="10"> <br>
<br>
<?php @require_once('../includes/copyright.php'); ?>
</span><br>
<br>
</div></td>
</tr>
</table></td>
</tr>
</table>
</td>
<td width="100" bgcolor="#393989"> </td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
</body>
</html>
<?php mysql_close() ?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by gregorious on Thu Jul 12, 2007 10:43 am, edited 2 times in total.
- gregorious
- Forum Commoner
- Posts: 34
- Joined: Wed Aug 23, 2006 9:55 am
- Location: Orlando, FL
just a assumtption
I assume there is something like "VARIABLE SCOPE" that prevents the $id [variable/record] from working in the "UPLOAD / FILENAME / IMAGECOPYRESAMPLED / SAVE" portion of code that begins:
after,
the $id [variable/record] works again. I am one year old PHP coder, and this one has me stumped.
Greg
Code: Select all
<?php
//load the config file
include("../includes/images-config.php");
//if the for has submittedd
if (isset($_POST['uploadimage'])){Code: Select all
}
echo "<div align='center'><br><br><br>Residential IMAGE uploaded!</div><br><br><br>";
}else{Greg
- gregorious
- Forum Commoner
- Posts: 34
- Joined: Wed Aug 23, 2006 9:55 am
- Location: Orlando, FL
almost there over the hump
Getting the global variable to work inside of the local IF statement is the challenge; and I finally got it to show up by adding the $_POST line at the beginning of the local IF statement.
However, I get an ERROR (that contains the record id 10, which is good), <?php echo 10 ;?> but the error also shows the code I used outside of the local IF statement to ECHO the record.
Error that contains variable/record $id (10).
I just need to pass the global variable $id into the local IF statment without the <?php echo ;?> code.
Thanks in advance for any help.
Greg
However, I get an ERROR (that contains the record id 10, which is good), <?php echo 10 ;?> but the error also shows the code I used outside of the local IF statement to ECHO the record.
Code: Select all
<?php
//load the config file
include("../includes/images-config.php");
//if the for has submittedd
if (isset($_POST['uploadimage'])){
$id = $_POST['id'];Code: Select all
Warning: imagejpeg() [function.imagejpeg]: Unable to open
'../images/residential/pic-<?php echo 10; ?>-108093261.jpg'
for writing: Invalid argument in d:\www\realty\admin\
add_residential_image01.php on line 270Thanks in advance for any help.
Greg
- gregorious
- Forum Commoner
- Posts: 34
- Joined: Wed Aug 23, 2006 9:55 am
- Location: Orlando, FL
Line 270 is just below
Line 270 is just below the "save image" comment line, my goal here is to insert the record ID into the file name of the IMAGE. But I am getting <?php echo 10 ;?> instead of just the record number 10.
Code: Select all
// explode it to get the extention
$parts = explode(".", $rand_name);
$pic_name = 'pic-'.$id.'-'.$parts[0].$parts[1];
//save image
ImageJpeg ($pic_resized_img,"../$path_residential_pics$pic_name.$file_ext");
ImageDestroy ($pic_resized_img);
ImageDestroy ($pic_new_img);
}- gregorious
- Forum Commoner
- Posts: 34
- Joined: Wed Aug 23, 2006 9:55 am
- Location: Orlando, FL
Problem resolved
I was told to put in the hidden value for $id into the form after the orignal post - except I also included the full <?php echo ?> command too.
ugh! oh, good greif.
I feel like such a blockhead.
Code: Select all
<input name='id' type='hidden' value='$id' />
//edited to show source of error and correct value
// was <input name='id' type='hidden' value='<?php echo $id ?>' />I feel like such a blockhead.