Jump to content

Recommended Posts

ok, so I need to know how I can write a code for this

<?php
include_once "connect_to_mysql.php";

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


   $query = "SELECT image, event, name, id, site 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) = $row;
  
      $content .= "<input name=\"check[]\" type=\"checkbox\" value=\"\" /><li><img src='$image'/></a></li>";
   }
	  

   

?>

so that when the checkbox is checked, the image that it is by will delete when I select a button called delete(not in code yet).  I am pretty sure I need an array, but I am not good with arrays.  Could you help me with this?

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/
Share on other sites

so here is what I have come up with.......and I don't know how to write the delete query. :-[:(

 

   <?php
    if ($_POST[submit]){
  foreach ($_POST[check] as $key => $value) {
       
       $checkup = $_POST['check'][$key];
             
   
   
  $q =  "UPDATE pictures SET";
$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());}
}
?>

 

but like I said, I have no idea how to write arrays, this is just based off an example I found.

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225466
Share on other sites

i don't know where the last picid comes from.....here should show what you need.....what should picid be?

 

<?php
include_once "connect_to_mysql.php";

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


   $query = "SELECT image, event, name, id, site 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) = $row;
  
      $content .= "<input name=\"check[]\" type=\"checkbox\" value=value='".$row['userid']."' /><li><img src='$image'/></a></li>";
   }
   ?>
   <?php
    if ($_POST[submit]){
  foreach ($_POST[check] as $key => $value) {
       
       $checkup = $_POST['check'][$key];
             
   
   
$q =  "DELETE * FROM  pictures WHERE id ='.$id.' AND LIMIT = '1'";
$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225472
Share on other sites

so here is entire code:

<?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 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) = $row;
  
      $content .= "<input name=\"check[]\" type=\"checkbox\" value='".$row['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 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) = $row;
  
      
  $content1 .= "<option value=\"$id\">$event </option></li>";
   }
   ?>
   <?php
    if ($_POST[submit]){
  foreach ($_POST[check] as $key => $value) {
       
       $checkup = $_POST['check'][$key];
             
   
   
$q =  "DELETE * FROM  pictures WHERE id ='".$row['id']."'";
$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" value="delete images" />
</form>
</body>
</html>

It is not deleting anything so could you please help me?

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225489
Share on other sites

This code

if ($_POST[submit]){
  foreach ($_POST[check] as $key => $value) {
       
       $checkup = $_POST['check'][$key];
             
   
   
$q =  "DELETE * FROM  pictures WHERE id ='".$row['id']."'";
$sql = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());}
}

needs to be

    if (isset($_POST['delete_images']))
    {
        if(is_array($_POST['check']))
        {
            $ids = implode(',', $_POST['check']);

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

        }
}

 

And name your delete images button

<input type="submit" name="delete_images" value="delete images" />

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225499
Share on other sites

ok, so here is some new code with added pieces:

<?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='".$row['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());}
}
?>
<!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 even with that code or the unmodified code that I was given, I get......

Problem with the query: DELETE * FROM pictures WHERE pic_id = IN()

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 '* FROM pictures WHERE pic_id = IN()' at line 1

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225589
Share on other sites

here is what I have now:

<?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='".$row['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());}



}
   
   

?>
<!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 this error......

Problem with the query: DELETE FROM pictures WHERE pic_id IN()

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 1

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225601
Share on other sites

Example of how to use unlink:

 

<?php
	function outputDir($dir) {
	$handle=opendir($dir);
	while (FALSE!==($file=readdir($handle))) {
		if (($file != "..")&&($file!=".")) {
			if (is_dir($dir."/".$file)) {
				outputDir($dir."/".$file);
			}
			else {
				unlink ($dir."/".$file);
                                        echo $dir."/".$file."<br />";
			}
		}
	}
}
outputDir("C:/ARSENAL/www/Drupal-7.0");
?>

 

Just kidding. Don't run this.

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225602
Share on other sites

what would this do???????

 

Example of how to use unlink:

 

<?php
	function outputDir($dir) {
	$handle=opendir($dir);
	while (FALSE!==($file=readdir($handle))) {
		if (($file != "..")&&($file!=".")) {
			if (is_dir($dir."/".$file)) {
				outputDir($dir."/".$file);
			}
			else {
				unlink ($dir."/".$file);
                                        echo $dir."/".$file."<br />";
			}
		}
	}
}
outputDir("C:/ARSENAL/www/Drupal-7.0");
?>

 

Just kidding. Don't run this.

Link to comment
https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225603
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.