searls03 Posted June 5, 2011 Share Posted June 5, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/ Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 oh yea, one more thing.....it deletes from table called "pictures", which contains a url to the picture on this site, but if I could get the url and the picture to delete, in a directory called "images".......that would be the best!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225455 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 Would you not have to put the value in the checkbox value ? value= '.$row['id'].' So you want some one to write you the code Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225456 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 sorry, I would have put that in later.....but yes, I would have. sorry about that. any other help? Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225457 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 Try writing the code in full then come back because you are asking for some one to write the code for you and not even trying. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225459 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 if you couldn't read, I am not good at array codes.......could you please post a link to the phpmanual as to where to start.....I searched arrays on it but it comes back with too many links and I don't know what to choose. please help Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225460 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225466 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 Hard to know but will be like that for delete everything from that row had to make up variables because you have no code or datasbase feilds for me to work with. $q = "DELETE * FROM pictures WHERE id ='.$id.' AND LIMIT = '1'"; Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225470 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 sorry bout that.......just trying to get a template worked out...... Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225471 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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());} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225472 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 Sorry my fault not reading back again $q = "DELETE * FROM pictures WHERE id ='.$id.' AND LIMIT = '1'"; Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225474 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 I do still need some help with making it delete from the server, I have no idea or anything on how this code would look. sorry. could you help me with code or give me some links or something? Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225483 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225489 Share on other sites More sharing options...
wildteen88 Posted June 5, 2011 Share Posted June 5, 2011 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" /> Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225499 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 Wold that delete all the pictures that I select????? Also how do I delete from server??? Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225562 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225589 Share on other sites More sharing options...
Pikachu2000 Posted June 5, 2011 Share Posted June 5, 2011 That isn't correct syntax for a DELETE query. MySQL manual entry. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225593 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 thats what I was given by somebody, I hadn't thought it was. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225594 Share on other sites More sharing options...
jcbones Posted June 5, 2011 Share Posted June 5, 2011 Pik is saying that the delete query should be: $q = "DELETE FROM pictures WHERE pic_id IN($ids)"; If you want to delete the image file, then use unlink(). Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225598 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225601 Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225602 Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225603 Share on other sites More sharing options...
jcbones Posted June 5, 2011 Share Posted June 5, 2011 Your query has no 'ids' in it. That is the problem. You need to make sure you are getting them. echo '<pre>'; print_r($_POST['check']); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225604 Share on other sites More sharing options...
jcbones Posted June 5, 2011 Share Posted June 5, 2011 It will delete every file in your directory that you give it. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225605 Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 searls03, output the delete sql and see what the query is sending. echo $q; -- As for my not so humerous comment. It would delete everything. Quote Link to comment https://forums.phpfreaks.com/topic/238482-delete-images/#findComment-1225606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.