Web Analytics Made Easy -
StatCounter How can I Delete Images separately ? - CodingForum

Announcement

Collapse
No announcement yet.

How can I Delete Images separately ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I Delete Images separately ?

    I have the following code which displays images from database, specifically images that the user has uploaded, I would like to give the user the ability to delete any photographs they have uploaded. Each photograph has its own photo id if thats any use.

    I have tried to do this and when ever I try to delete anything I just get the word array shown beside the photograph.

    Any help here would be very much appreciated. Regards

    PHP Code:
    <?php
               
    require_once('auth.php');
        include(
    "config.php");

        
    // initialization
        
    $result_array = array();
            
    $uploadedby $_SESSION['SESS_MEMBER_ID'];

        {
            
    $number_of_thumbs_in_row 4;

            
    $result mysql_query"SELECT photo_id,photo_caption,photo_filename FROM gallery_photos where uploaded_by='$uploadedby'" );
            while( 
    $row mysql_fetch_array$result ) )             
            {
            
    $result_array[] = "<a href='fullimage.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/".$row[2]."' border='1' alt= 'height='100' width='100' ".$row[1]."' /></a>";
            }
            
    mysql_free_result$result );        

                
    $result_final "<tr>\n";
        
                foreach(
    $result_array as $thumbnail_link)
                {
                    if(
    $counter == $number_of_thumbs_in_row)
                    {    
                        
    $counter 1;
                        
    $result_final .= "\n</tr>\n<tr><td><p></p></td><td><p></p></td><td><p></p></td><td><p></p></td></tr>\n<tr>\n";
                    }
                    else
                    
    $counter++;

                    
    $result_final .= "\t<td align='center'><table border='1'><tr><td>".$thumbnail_link."</td><td>delete</td></tr></table></td>\n";
                }
        
                if(
    $counter)
                {
                    if(
    $number_of_photos_in_row-$counter)
                
    $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n";

                    
    $result_final .= "</tr>";
                }
            
        }


    echo <<<__HTML_END

    <html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />

        <style type="text/css" media="all">@import "css/master.css";</style>
        <link href="css/master.css" rel="stylesheet" type="text/css">

    </head>

    <body bgcolor="#434547">

      <div id="page-container">
        
           <div id="header"><h1><img src="../images/ice.jpg"/></h1>
                         <h2><img src="../images/layout/title.jpg"/></h2>
           </div>


        
           <div id="menu">



                <div id="login">
      <table width="50" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr>
           <td><a href="logout.php">Logout</a><td>
        </tr>
      </table>


                </div>


                <div id="navigation">

                   <ul id="minitabs">
                       <li><a href="index.php">Home</a></li>
                       <li><a href="form.php">Upload</a></li>
                       <li><a href="viewgallery.php">Gallery</a></li>
                       <li><a href="register.php">Register</a></li>
                   </ul>
                </div>

              

           </div>



           <div id="content">
          Welcome 

    __HTML_END;


    echo  
    $_SESSION['SESS_FIRST_NAME'];

    echo <<<__HTML_END



          <a href="member-profile.php">My Profile</a>

    <p>This is a display of all pictures you have uploaded to the database</p>

              <table width='860px' align='center' border='0'>
                  
    $result_final        
              </table>
           </div>




        <div id="footer">
           <p>
              All footer information will be placed here
               </p>
        </div>

      </div>


    </body>
    </html>
    __HTML_END;
    ?>

  • #2
    hi Mark, use an HTML form to help user to select photos to delete, when they press the submit button, send an array of photo_ids to some php code on the server.

    on the sever, use
    PHP Code:
    foreach 
    to delete the photo from the database. The embedded Sql in your php you need is
    PHP Code:
    "delete from gallery_photos where photo_id = $current_photo_id
    $current_photo_id is the variable you set when you inspect each photo_id in your array
    live every day as if it was your first

    Comment


    • #3
      Originally posted by mark9766 View Post

      $result_final .= "\t<td align='center'><table border='1'><tr><td>".$thumbnail_link."</td><td>**************</td></tr></table></td>\n";


      [/PHP]
      at the point in blue above i wanted to have a button from a form so that when clicked it would grab the particular images pid and then submit it to another page where a code can be ran which will delete it from the database:
      is this possible within this code ?

      <form id="deleteForm" name="deleteForm" method="post" action="delete-exec.php">
      <table>
      <tr>
      <td>
      <input type="delete" name="delete" value="delete image" />
      </td>
      </tr>
      </table>
      <form>

      Comment

      Working...
      X