Jump to content

delete images


searls03

Recommended Posts

so now I changed it to this......

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="/login.php">log in</a> to access your account';
   exit(); 
}

//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$userid = $_SESSION['id'];
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$name = $row["name"];
$phone = $row["phone"];
$username = $row["username"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$cell = $row["cell"];
$email = $row["email"];
$accounttype = $row["accounttype"];
$rank = $row["rank"];
$badges = $row["badges"];
$userid = $row["userid"];

}

?>
<?php
include_once "connect_to_mysql.php";

// if no id is specified, list the available articles


   $query = "SELECT image, event, name, id, site, pic_id FROM pictures where id='".$_GET['id']."'";
   $result = mysql_query($query) or die('Error : ' . mysql_error());
  
   // create the article list

   while($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      list($image, $event, $name, $id, $site, $pic_id) = $row;
  
      $content .= "<input name=\"check[]\" type=\"checkbox\" value=$pic_id /><img src='/$image' width='190' height='150'/></a><br />
";}
   ?>
   <?php
include_once "connect_to_mysql.php";

// if no id is specified, list the available articles


   $query = "SELECT image, event, name, id, site, pic_id FROM pictures GROUP BY event";
   $result = mysql_query($query) or die('Error : ' . mysql_error());
  
   // create the article list

   while($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      list($image, $event, $name, $id, $site, $picid) = $row;
  
      
  $content1 .= "<option value=\"$id\">$event </option></li>";
   }
   ?>
   <?php
if (isset($_POST['delete_images']))
    {
        if(is_array($_POST['check']))
        {
            $ids = implode(',', $_POST['check']);

            
echo '<pre>'; print_r($_POST['check']); echo '</pre>'; 
   


   
$q =  "DELETE FROM  pictures WHERE pic_id = IN($ids)";$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()) ; }



}
   

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="picsman.php" method="get">
  <select name="id">
  <?php echo $content1; ?>
</select>
  <input type="submit" name="select" id="select" value="Select Event" />
</form>
<form action="picsman.php" method="post">
<?php
echo $content; 
?>
<input type="submit" name="delete_images" value="delete images" /></form>

</body>
</html>

 

but now I get:

Array

(

    [0] => 11

    [1] => 12

)

 

Problem with the query: DELETE FROM pictures WHERE pic_id = IN(11,12)

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 'IN(11,12)' at line 1

is this correct way to delete from server?

<?php
session_start(); // Must start session first thing
/* 
Created By Adam Khoury @ www.flashbuilding.com 
-----------------------June 20, 2008----------------------- 
*/
// Here we run a login check
if (!isset($_SESSION['id'])) { 
   echo 'Please <a href="/login.php">log in</a> to access your account';
   exit(); 
}

//Connect to the database through our include 
include_once "connect_to_mysql.php";
// Place Session variable 'id' into local variable
$userid = $_SESSION['id'];
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$name = $row["name"];
$phone = $row["phone"];
$username = $row["username"];
$address = $row["address"];
$city = $row["city"];
$state = $row["state"];
$zip = $row["zip"];
$cell = $row["cell"];
$email = $row["email"];
$accounttype = $row["accounttype"];
$rank = $row["rank"];
$badges = $row["badges"];
$userid = $row["userid"];

}

?>
<?php
include_once "connect_to_mysql.php";

// if no id is specified, list the available articles


   $query = "SELECT image, event, name, id, site, pic_id FROM pictures where id='".$_GET['id']."'";
   $result = mysql_query($query) or die('Error : ' . mysql_error());
  
   // create the article list

   while($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      list($image, $event, $name, $id, $site, $pic_id) = $row;
  
      $content .= "<input name=\"check[]\" type=\"checkbox\" value=$pic_id /><img src='/$image' width='190' height='150'/></a><br />
";}
   ?>
   <?php
include_once "connect_to_mysql.php";

// if no id is specified, list the available articles


   $query = "SELECT image, event, name, id, site, pic_id FROM pictures GROUP BY event";
   $result = mysql_query($query) or die('Error : ' . mysql_error());
  
   // create the article list

   while($row = mysql_fetch_array($result, MYSQL_NUM))
   {
      list($image, $event, $name, $id, $site, $picid) = $row;
  
      
  $content1 .= "<option value=\"$id\">$event </option></li>";
   }
   ?>
   <?php
if (isset($_POST['delete_images']))
    {
        if(is_array($_POST['check']))
        {
            $ids = implode(',', $_POST['check']);

            
   


   
$q =  "DELETE FROM  pictures WHERE pic_id IN($ids)";$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()) ; }

if(is_file("$image")) {
unlink("$image");
}



}
   

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="picsman.php" method="get">
  <select name="id">
  <?php echo $content1; ?>
</select>
  <input type="submit" name="select" id="select" value="Select Event" />
</form>
<form action="picsman.php" method="post">
<?php
echo $content; 
?>
<?php
if (isset($_GET['id'])) {
?>
<input type="submit" name="delete_images" value="delete images" /></form>
<?php } ?>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.