SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $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{ , and then the $id [variable/record] works again in the HTML, so what am I missing?

    Thanks in advance,
    Greg
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $id is being defined somewhere. you need to find out where, and move it earlier in the code.

  3. #3
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page code below.

    Page code below.

    $id is only equated in a MYSQL "FROM residential WHERE res_id='$id'" and in "FROM image WHERE image_res_id='$id'" and is called in the HTML ($id) and returns the correct record, but not in the UPLOAD / FILENAME / IMAGECOPYRESAMPLED / SAVE code.

    PHP Code:

    <?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">&nbsp;</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>&lt; back to <a href="admin.php">admin</a>&nbsp;&nbsp; - 
              &nbsp;&nbsp;exit to <a href="../index.htm">website</a> &gt;<br>
              </span><br>
              <img src="../images/spacer-grn.jpg" width="10" height="10"> &nbsp; 
              <img src="../images/spacer-grn.jpg" width="10" height="10"> &nbsp; 
              <img src="../images/spacer-grn.jpg" width="10" height="10"> </div>
                  </p></td>
          </tr>
        </table>
            </td>
        <td width="100" bgcolor="#393989">&nbsp;</td>
      </tr>
    </table>

    <table width="760" border="0" cellspacing="0" cellpadding="10">
      <tr align="left" valign="bottom">
        <td width="100" bgcolor="#00833D">&nbsp;</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&nbsp;&nbsp; <?php echo $id?></span><br>          
                    <span class="listing01"><strong><?php echo $restype ;?></strong><br>
                      <?php echo $resstreet01 ;?><br>
                      <?php echo $rescity ;?>&nbsp;&nbsp;
                      <?php echo $resstate ;?>&nbsp;&nbsp;<?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">&nbsp;</td>
                      <td align="left" valign="middle">&nbsp;</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_img0000$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_img0000$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"> &nbsp;
                     <img src="../images/spacer-grn.jpg" width="10" height="10"> &nbsp; 
                     <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">&nbsp;</td>
      </tr>
    </table>

    </td>
    </tr>
    </table>
    <p>&nbsp;</p>
    </body>
    </html>
    <?php mysql_close() ?>
    Last edited by gregorious; Jul 12, 2007 at 08:26. Reason: edited to show source of error and correct value
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    do you have register_globals on?

  5. #5
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes...

    register_globals On On

    Greg
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  6. #6
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    first off, register_globals is a REALLY bad idea. do you know that?

  7. #7
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am one year old PHP coder, and my NETSOL.com server has them turned on; so I mirrored their settings.

    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:

    Code:
    <?php 
        //load the config file 
        include("../includes/images-config.php"); 
    
        //if the for has submittedd 
        if (isset($_POST['uploadimage'])){
    after,

    Code:
          } 
                echo "<div align='center'><br><br><br>Residential IMAGE uploaded!</div><br><br><br>"; 
    
        }else{
    the $id [variable/record] works again.
    Greg
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  8. #8
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    this is not a variable scope problem. you're simply not passing it on. in your form, you need to add another hidden value for id.

    however, i strongly recommend that you read up on register_globals (starting with the PHP manual) and learn to program without it. you should also contact your host and find out how to disable register_globals. nowadays, using a combination of .htaccess and php.ini you can change PHP settings that you normally would not be able to in a shared host environment.

  9. #9
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for you help.

    You got me really thinking about register_globals now, I know I was stumped for about eight hours one time, because they were off.

    I will read up on the subject. Thanks. Longneck
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  10. #10
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    PHP Code:
        <?php
        
    //load the config file
        
    include("../includes/images-config.php");

        
    //if the for has submittedd
        
    if (isset($_POST['uploadimage'])){
               
    $id $_POST['id'];
    Error that contains variable/record $id (10).

    Code:
    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 270
    I just need to pass the global variable $id into the IF statment without the <?php echo ;?> code.

    Thanks in advance for any help.
    Greg
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    please post the code around line 270 Greg
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Line 270 is just below the comment line

    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.

    PHP Code:
    // 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);

    Last edited by gregorious; Jul 12, 2007 at 07:47.
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com

  13. #13
    SitePoint Zealot gregorious's Avatar
    Join Date
    Aug 2006
    Location
    Honolulu, HI
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    this is not a variable scope problem. you're simply not passing it on. in your form, you need to add another hidden value for id.

    Thanks, this was the answer and the source of my follow up issues. I put in the hidden value for $id - except I also included the full <?php echo ?> command too.

    PHP Code:
    <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 ?>' />
    ugh! oh, good greif. I feel like such a blockhead.

    Thanks Longneck, after this one I am going to toss back a few longneck buds in tribute.
    G. Armento - Design, Multimedia, Illustration, Photography
    -------------------------------------------------------
    www.communications-by-design.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •