1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Delete album and items related to the album HELP

Discussion in 'PHP' started by macaela, Sep 17, 2010.

  1. #1
    i do think is a small mistake i making can u please have a look if u can
    ok here's the problem i am trying to delete an album within the album should also delete the photos related to that album this what i tried gives this error
    Delete image failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

    my tables are
    table albums fields album_id, album_name, album_owner, sub_album
    table photos fields, photo_id, photo_name, photo_extension, photo_proper photo_owner, photo_date, photo_comments, photo_size, album_id

    photo_proper is the name image stored in folder

    
    <?php
    
    define('ROOT_DIR', './');
    
    define('PROPER', TRUE);
    
    /**
    
    * include common files
    
    */
    
    include_once(ROOT_DIR. 'includes/common.inc.php');
    
    
    
    
    
    // No album id has been selected
    
    if (isset($_GET['albums'])) 
    
       // get the album name since we need to display
    
       // a message that album 'foo' is deleted
    
       $result = mysql_query("SELECT album_id, album_name, album_owner, sub_album
    
                              FROM albums
    
                              WHERE album_id = $album_id")
    
                 or die('Delete image failed. ' . mysql_error());
    
       if (mysql_num_rows($result) == 1) {
    
          $row        = mysql_fetch_assoc($result);
    
          $album_id  = $row['album_id'];
    
          $album_name = $row['album_name'];
    
    
    
          // get the image filenames first so we can delete them
    
          // from the server
    
          $result = mysql_query("SELECT photo_id, photo_id
    
                                 FROM photos
    
                                 WHERE album_id = $album_id")
    
                    or die(mysql_error());
    
          while ($row = mysql_fetch_assoc($result)) {
    
          
    
        define("GALLERY_IMG_DIR", "./photos/");
    
    
    
          
    
          unlink(GALLERY_IMG_DIR . $row['photo_proper']);
    
          unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']);
    
    
    
          }
    
    
    
          $result = mysql_query("DELETE FROM photos
    
                                 WHERE album_id = $album_id")
    
                    or die('Delete image failed. ' . mysql_error());
    
          $result = mysql_query("DELETE FROM album
    
                                 WHERE album_id = $album_id")
    
                    or die('Delete album failed. ' . mysql_error());
    
    
    
          // album deleted successfully, let the user know about it
    
          echo "<p align=center>Album '$album_name' deleted.</p>";
    
       } else {
    
          echo "<p align=center>Cannot delete a non-existent album.</p>";
    
       }
    
    
    
    
    
    
    
    ?>
    
    
    PHP:
    try 2 error line 5
    <?php
    define('ROOT_DIR', './');
    define('PROPER', TRUE);
    /**
    * include common files
    */
    include_once(ROOT_DIR. 'includes/common.inc.php');
    
    
    // No album id has been selected
    if (isset($_GET['albums'])) 
     {
       // get the image file name so we
       // can delete it from the server
       $sql = "SELECT album_id, album_name, album_owner, sub_album
    
               FROM albums
    
               WHERE album_id = {$_GET['albums']}";
    
       $result = mysql_query($sql)
    
                 or die('Delete photo failed. ' . mysql_error());
    
       if (mysql_num_rows($result) == 1) {
    
          $row = mysql_fetch_assoc($result);
    
          // get the image filenames first so we can delete them
          // from the server
         $sql = "SELECT photo_id, photo_proper
    
               FROM photos
    
               WHERE photo_id = {$_GET['photos']}";
    
       $result = mysql_query($sql)
    
                 or die('Delete photo failed. ' . mysql_error());
    
       if (mysql_num_rows($result) == 1) {
    
          $row = mysql_fetch_assoc($result);
          
    define("GALLERY_IMG_DIR", "./photos/");
    
          // remove the image and the thumbnail from the server
          unlink(GALLERY_IMG_DIR . $row['photo_proper']);
    
          unlink(GALLERY_IMG_DIR . 'thumbs/' . $row['photo_proper']);
          
          // and then remove the database entry
    
          $sql = "DELETE FROM photos
    
                  WHERE photo_id = {$_GET['photos']}";
          $result = mysql_query("DELETE FROM album
                                 WHERE album_id = $album_id")
                    or die('Delete album failed. ' . mysql_error());
    
          // album deleted successfully, let the user know about it
          echo "<p align=center>Album '$album_name' deleted.</p>";
       } else {
          echo "<p align=center>Cannot delete a non-existent album.</p>";
       }
    
    }
    }
    
    ?>
    PHP:
     
    macaela, Sep 17, 2010 IP
  2. imperialDirectory

    imperialDirectory Peon

    Messages:
    395
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your script failed in the beginning:
    
       $result = mysql_query("SELECT album_id, album_name, album_owner, sub_album
                              FROM albums
                              WHERE album_id = $album_id")
                 or die('Delete image failed. ' . mysql_error());
    
    Code (markup):
    $album_id is not set yet so your query failed.

    You do have "if (isset($_GET['albums'])) " on top of it but it never assigns any value to $album_id
     
    imperialDirectory, Sep 17, 2010 IP