Can't get Update to work on this script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonski
    New Member
    • Jun 2007
    • 53

    #16
    instead of this
    [PHP]
    $photo_dir = '/./gallery/image_uploads/';
    $thumb_dir = '/./gallery/thumb_uploads/';[/PHP]

    change to this..

    [PHP]$photo_dir = '../../gallery/image_uploads/';
    $thumb_dir = '../../gallery/thumb_uploads/';[/PHP]

    where exactly is your script? and wheres the root path of you image files?

    example:
    directory structure...

    if you script is the same folder with the directory 'gallery'
    Code:
    php_scripts/
        gallery/
             image_uploads/
                    img.jpeg
             thumb_uploads/
                    thmb.jpeg
    
        edit_picture.php
    then you should set the dir path like this

    [PHP]
    $photo_dir = 'gallery/image_uploads/';
    $thumb_dir = 'gallery/thumb_uploads/';
    [/PHP]

    but if outside or another folder like this
    Code:
    images/
        gallery/
             image_uploads/
                    img.jpeg
             thumb_uploads/
                    thmb.jpeg
    php_scripts/
        edit_picture.php
    then set it up like this

    [PHP]
    $photo_dir = '../images/gallery/image_uploads/';
    $thumb_dir = '../images/gallery/thumb_uploads/';
    [/PHP]

    '..' means go up one level

    ^___^

    Comment

    • bonski
      New Member
      • Jun 2007
      • 53

      #17
      thats good... ^___^..!!

      Comment

      • DavidPr
        New Member
        • Mar 2007
        • 155

        #18
        ^___^ - what does this mean?


        Question:
        [PHP]$image_sql = "SELECT * FROM $table WHERE id='".$id."'";
        $image_qry = mysql_query($im age_sql);
        $row = @mysql_fetch_ob ject($image_qry );

        //name of image file
        $image_name = $row->image_name;[/PHP]
        How were you able to get the image_name from the above?

        Also: The above was to delete image information in the database and the image on the server. The pictures are filed under a specific category or album. I have a script that will delete the category and I would like to take this one step further. If I decide to delete a category or album I would like for all of the pictures associated with this category or album to be deleted as well. Both from the server and the picture table ($table).

        Will the big code below do the job or would this here have to be modified from image to images[PHP] //name of image file
        $image_name = $row->image_name;

        if(unlink($phot o_dir.$image_na me) && unlink($thumb_d ir.$image_name) ){ [/PHP]

        [PHP]<?php
        if($_GET['cmd']=="delete" && isset($_GET['cat_id']))

        {

        $cat_id = $_GET["cat_id"];

        $photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
        $thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';


        //getting the data of the image
        $image_sql = "SELECT * FROM $table WHERE cat_id='".$cat_ id."'";
        $image_qry = mysql_query($im age_sql);
        $row = @mysql_fetch_ob ject($image_qry );

        //name of image file
        $image_name = $row->image_name;

        if(unlink($phot o_dir.$image_na me) && unlink($thumb_d ir.$image_name) ){

        $sql = "DELETE FROM $table WHERE cat_id=$cat_id" ;
        $result = mysql_query($sq l);

        if($result)

        {
        echo "<br><br><p align='center'> <span style='color:re d'><b>The Pictures in this album have been Deleted!<br><br >";
        }

        }
        else
        {

        echo 'ERROR: Unable to delete image file!';
        }


        $sql = "DELETE FROM $cat WHERE cat_id=$cat_id" ;
        $result = mysql_query($sq l);

        if($result)
        {
        echo "<br><br><p align='center'> <span style='color:re d'><b>This Album has been Deleted!<br><br >";

        }
        else
        {

        echo 'ERROR: Unable to Delete this Album!';
        }

        }
        ?>[/PHP]

        Comment

        • bonski
          New Member
          • Jun 2007
          • 53

          #19
          Originally posted by DavidPr
          ^___^ - what does this mean?


          Question:
          [PHP]$image_sql = "SELECT * FROM $table WHERE id='".$id."'";
          $image_qry = mysql_query($im age_sql);
          $row = @mysql_fetch_ob ject($image_qry );

          //name of image file
          $image_name = $row->image_name;[/PHP]
          How were you able to get the image_name from the above?
          ^___^ means a big smile... hahaha...

          so from this query

          [PHP]$image_sql = "SELECT * FROM $table WHERE id='".$id."'";[/PHP]

          it will return the whole row of the image file record from the table which its 'id' is equal to the value you provide from the variable '$id'

          well this line is getting the image_name field from your table
          i used the function mysql_fetch_obj ect(), so it looks like this
          [PHP]$image_name = $row->image_name;[/PHP]
          using -> as a pointer(im not sure bout the name.. but i call it pointer..)

          so $image_name contains already the name of the image file from the table...

          then thats the time you concatenate it with the directories when you unlink..

          ^____^ bonski

          Comment

          • DavidPr
            New Member
            • Mar 2007
            • 155

            #20
            Thanks for that explanation. I was editing my previous post at the same time you made your post. You beat me to the "Enter" key.

            Was hoping you would have a peek at it and tell me what you think.
            Thank you.

            Comment

            • bonski
              New Member
              • Jun 2007
              • 53

              #21
              Originally posted by DavidPr
              Thanks for that explanation. I was editing my previous post at the same time you made your post. You beat me to the "Enter" key.

              Was hoping you would have a peek at it and tell me what you think.
              Thank you.
              sure buddy...!!! you're welcome.... ^___-. im looking forward for that...!

              Comment

              • DavidPr
                New Member
                • Mar 2007
                • 155

                #22
                Thanks I appreciated the help.

                The script you were helping me with was to delete one picture from the server and that picture's information from the database. The categories the pictures are associated with are in a table called by the variable $cat. The fields or rows are - cat_id, cat_name and cat_desc.

                What I would like to do is to alter the script we just completed, so that I can:
                • Delete a category from the $cat table.
                • Delete all the pictures on the server that are filed under that category's id number in the database table - $table.
                • Delete all the information in the $table pertaining to the pictures under the deleted category's id number.


                The code below will do everything except it only removes one picture from the server. Is it possible to remove all the pictures on the server that are filed under the category being deleted?

                Maybe change image_name to image_name(s)?[PHP]//name of image file
                $image_name = $row->image_name;

                if(unlink($phot o_dir.$image_na me) && unlink($thumb_d ir.$image_name) )
                { [/PHP]

                Here's what I have:
                [PHP]<?php
                if($_GET['cmd']=="delete" && isset($_GET['cat_id']))
                {

                $cat_id = $_GET['cat_id'];

                $photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
                $thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';


                //getting the data of the image
                $image_sql = "SELECT * FROM $table WHERE cat_id='".$cat_ id."'";
                $image_qry = mysql_query($im age_sql);
                $row = @mysql_fetch_ob ject($image_qry );

                //name of image file
                $image_name = $row->image_name;

                if(unlink($phot o_dir.$image_na me) && unlink($thumb_d ir.$image_name) )
                {
                $query = "DELETE FROM $table WHERE cat_id='".$cat_ id."'";
                $result = mysql_query($qu ery) or die('Error, query failed mysql said <b>'.mysql_erro r().'</b>');
                if($result)
                {
                echo "<br><br><p align='center'> <span style='color:re d'><b>The Pictures in this album have been Deleted!<br><br >";
                }
                }
                else
                {
                echo "ERROR: Unable to delete image file!";
                }


                $query = "DELETE FROM $cat WHERE cat_id='".$cat_ id."'";
                $result = mysql_query($qu ery) or die('Error, query failed mysql said <b>'.mysql_erro r().'</b>');
                if($result)
                {
                echo "<br><br><p align='center'> <span style='color:re d'><b>This Album has been Deleted!<br><br >";
                }
                else
                {
                echo "ERROR: Unable to Delete this Album!";
                }

                } //end of isset
                ?>[/PHP]

                Comment

                • DavidPr
                  New Member
                  • Mar 2007
                  • 155

                  #23
                  Would a while statement work? If so, would I still perform "If statement" shown below the while statement to make sure that the image files were unlinked so that it could move on to deleting the information from the database?

                  [PHP]<?php
                  if($_GET['cmd']=="delete" && isset($_GET['cat_id']))
                  {

                  $cat_id = $_GET['cat_id'];

                  $photo_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/image_uploads/';
                  $thumb_dir = $_SERVER['DOCUMENT_ROOT'].'/gallery/thumb_uploads/';


                  //getting the data of the image
                  $image_sql = "SELECT * FROM $table WHERE cat_id='".$cat_ id."'";
                  $image_qry = mysql_query($im age_sql);
                  $row = @mysql_fetch_ob ject($image_qry );

                  //name of image file
                  $image_name = $row->image_name;

                  $num = 0;
                  while ($image_name > $num);
                  {
                  unlink($photo_d ir.$image_name) && unlink($thumb_d ir.$image_name) ;
                  $num++;
                  }

                  if(unlink($phot o_dir.$image_na me) && unlink($thumb_d ir.$image_name) )
                  {

                  $query = "DELETE FROM $table WHERE cat_id='".$cat_ id."'";
                  $result = mysql_query($qu ery) or die('Error, query failed mysql said <b>'.mysql_erro r().'</b>');
                  if($result)
                  {
                  echo "<br><br><p align='center'> <span style='color:re d'><b>The Pictures in this album have been Deleted!<br><br >";
                  }
                  }
                  else
                  {
                  echo "ERROR: Unable to delete image file!";
                  }[/PHP]

                  Comment

                  • bonski
                    New Member
                    • Jun 2007
                    • 53

                    #24
                    What I would like to do is to alter the script we just completed, so that I can:
                    • Delete a category from the $cat table.
                    • Delete all the pictures on the server that are filed under that category's id number in the database table - $table.
                    • Delete all the information in the $table pertaining to the pictures under the deleted category's id number.
                    ok.. that script is only to delete one image file... and together with its record on the database... so deleting that image file record.. doesn't have to involved with the category itself.. right..

                    let me show some table relationship... table 1 is about category (e.g. animal photos) and table 2 is where the image file record is...

                    Code:
                    table 1: category
                    
                    cat_id         cat_name
                    
                      1             birds
                      2             dogs
                    
                    table 2: images
                    
                    img_id       cat_id        img_name
                    
                       1               2               dog1.jpeg
                       2               1                bird1.jpeg
                       3               1               bird2.jpeg
                    now... when you delete an image file... you going to query directly to table2 : images right? and it doesn't have to query from category anymore... because your just going to delete a certain image file...

                    [PHP]$delete_sql = "DELETE FROM ".$table_images ." WHERE img_id='".$imag e_id."'";[/PHP]

                    now... if your going to delete a category... you're going to check if there's any image file record under this category.. right?

                    ok here..

                    [PHP]

                    if(isset($_GET['c_id'])){

                    $cat_id = $_GET['c_id'];

                    $photo_dir = '/mysite.com/gallery/image_uploads/';
                    $thumb_dir = '/mysite.com/gallery/thumb_uploads/';
                    $count_record = 0;
                    $sql = "SELECT * FROM ".$table_images ." WHERE cat_id='".$cat_ id."'";
                    $qry = mysql_query($sq l);
                    $count_record = mysql_num_rows( $qry);

                    if($count_recor d != 0){

                    $counter = 0;
                    while($row = mysql_fetch_arr ay($qry, MYSQL_ASSOC)){
                    $image_id = $row['img_id'];
                    $image_name = $row['image_name'];

                    if(unlink($phot o_dir.$image_na me) && unlink($thumb_d ir.$image_name) ){
                    $sql = "DELETE FROM ".$table_images ." WHERE image_id='".$im age_id."'";
                    $result = mysql_query($sq l);
                    if($result){

                    $counter++;

                    }//endif($result)

                    }//end of if

                    }// end of while loop

                    if($count_recor d==$counter){
                    $delete_cat = "DELETE FROM ".$table_catego ry." WHERE cat_id='".$cat_ id."'";
                    $delete_cat_qry = mysql_query($de lete_cat);
                    }else{
                    echo 'ERROR: unable to delete category. unable to delete files!';
                    }

                    }else{
                    $delete_cat = "DELETE FROM ".$table_catego ry." WHERE cat_id='".$cat_ id."'";
                    $delete_cat_qry = mysql_query($de lete_cat);
                    }

                    }

                    [/PHP]

                    so this code will check if there are files under this category and delete all files existing if a category is deleted.. or if there's no files under this category it will just delete the category immediately... ^___^

                    Comment

                    • DavidPr
                      New Member
                      • Mar 2007
                      • 155

                      #25
                      I've a lot to learn. It works!

                      I didn't think so at first because it only showed my Web page heading after the script ran. This has happened to me in the past and was the result of a failed script as some point. I got used to seeing the confirmation messages of a successful action.

                      I added some confirmation messages, but I must not have put them in the correct locations since they didn't work when I re-ran the script.

                      This is great, thanks!

                      David

                      Comment

                      • bonski
                        New Member
                        • Jun 2007
                        • 53

                        #26
                        Originally posted by DavidPr
                        I've a lot to learn. It works!

                        I didn't think so at first because it only showed my Web page heading after the script ran. This has happened to me in the past and was the result of a failed script as some point. I got used to seeing the confirmation messages of a successful action.

                        I added some confirmation messages, but I must not have put them in the correct locations since they didn't work when I re-ran the script.

                        This is great, thanks!

                        David

                        glad to hear that.. you're welcome... have fun with you project... ^____^..

                        bonski

                        Comment

                        • DavidPr
                          New Member
                          • Mar 2007
                          • 155

                          #27
                          I've put this in several places in this last script, but I can't get it to show up on a successful category delete. Can you tell me which line to put it? Thanks again.

                          [PHP]echo "<br><br><p align='center'> <span style='color:re d'><b>The Album has been Deleted!<br><br >";[/PHP]

                          Comment

                          • bonski
                            New Member
                            • Jun 2007
                            • 53

                            #28
                            Originally posted by DavidPr
                            I've put this in several places in this last script, but I can't get it to show up on a successful category delete. Can you tell me which line to put it? Thanks again.

                            [PHP]echo "<br><br><p align='center'> <span style='color:re d'><b>The Album has been Deleted!<br><br >";[/PHP]
                            put this line after line 34 and after line 41 with this lines of code...

                            [PHP]

                            if($delete_cat_ qry){
                            echo "<br><br><p align='center'> <span style='color:re d'><b>The Album has been Deleted!<br><br >";
                            }
                            [/PHP]

                            bonski

                            Comment

                            Working...