searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 so how do i make ids present? that was a piece wildteen gave me. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 what does this do then? $ids = implode(',', $_POST['check']); Quote Link to comment Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 searls, you need to echo $q and print_r($_POST) and post them here. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 like this? Array ( [0] => ) DELETE FROM pictures WHERE pic_id = IN() (that what it gave me. Quote Link to comment Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 $_POST['check'] is empty. So when you implode $_POST['check'], you are imploding nothing. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 so how do I get this to work? Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 it has something to do with this......I changed checkbox to text and it is empty......how could I fix this?\ $content .= "<input name=\"check[]\" type=\"text\" value='".$row['pic_id']."' /><img src='/$image' width='190' height='150'/></a><br /> ";} Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 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 Quote Link to comment Share on other sites More sharing options...
jcbones Posted June 5, 2011 Share Posted June 5, 2011 If you would have followed my advice, you would have removed the equal (=) sign from your query. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 oh, sorry, I thought you had just forgot to put it in. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 5, 2011 Author Share Posted June 5, 2011 thanks, it works. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 6, 2011 Author Share Posted June 6, 2011 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> Quote Link to comment 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.