son Posted August 2, 2008 Share Posted August 2, 2008 I want to delete files from table with a selection via drop down and sumit button. The code is: $page_title = 'Delete files';include('inc/header.htm');echo "<div id=\"contentLeft\">";echo "<h1>Delete files</h1>";if (!isset($_GET['submitted'])) {echo "<p>On this page you can delete web pages. Simply select a file from drop-down menu and press Delete.<br /></p>";$query = "SELECT * FROM cms";$result = mysqli_query ($dbc, $query);echo "<form action=\"delete\" method=\"get\">";echo "<fieldset>";echo "<select name=\"df\">";echo "<option value=\"select\">Select</option>";while ($row = mysqli_fetch_array ($result, MYSQLI_ASSOC)) {echo "<option><a href=\"delete?df={$row['id']}\">{$row['file_name']}</a></option>\n"; }echo "</select>";echo "<span style=\"margin-left:20px;\"><input type=\"hidden\" name=\"submitted\" value=\"TRUE\" />";echo "<input type=\"submit\" name=\"submit\" value=\"Delete\" /></span>";echo "</fieldset>";echo "</form>";} else { if (isset($_GET['df'])) { $id = (int) $_GET['df']; } var_dump($df); $query = "DELETE FROM cms WHERE id = $df"; if ($result = mysqli_query ($dbc, $query)) { echo "The selected file has been deleted."; } else { echo "Your submission could not be processed due to a system error. Please contact customer service if problem persists."; }} The DELETE Query does work when I take $df out and use directly a number as:$query = "DELETE FROM cms WHERE id =7";var_dump($df) shows NULL Any ideas where I am going wrong?Son Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 2, 2008 Share Posted August 2, 2008 You're using a wrong identifier: if (isset($_GET['df'])) {$id = (int) $_GET['df'];}var_dump($id);$query = "DELETE FROM cms WHERE id = $id"; Link to comment Share on other sites More sharing options...
son Posted August 2, 2008 Author Share Posted August 2, 2008 You're using a wrong identifier:if (isset($_GET['df'])) {$id = (int) $_GET['df'];}var_dump($id);$query = "DELETE FROM cms WHERE id = $id"; Why is this one wrong (below is the relevant part with id):<a href=\"delete?df={$row['id']}\">{$row['file_name']}</a>?Son Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 2, 2008 Share Posted August 2, 2008 Because this is in your original code: if (isset($_GET['df'])) {$id = (int) $_GET['df'];} And this is not: if (isset($_GET['df'])) {$df = (int) $_GET['df'];} Link to comment Share on other sites More sharing options...
son Posted August 2, 2008 Author Share Posted August 2, 2008 Because this is in your original code:if (isset($_GET['df'])) {$id = (int) $_GET['df'];} And this is not: if (isset($_GET['df'])) {$df = (int) $_GET['df'];} Can see this. Still not working. I know why it is not working, but do not understand why. The line:<option><a href=\"delete?df={$row['id']}\">{$row['file_name']}</a></option>should have produced a querystring as df=2 for example, but it produces df=filename instead. Why would that be?Son Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 2, 2008 Share Posted August 2, 2008 Umm... Sounds like your database is messed up to me. Do you have phpMyAdmin or something similar that will let you view the database? Find the column named 'id' and check its values. Link to comment Share on other sites More sharing options...
son Posted August 2, 2008 Author Share Posted August 2, 2008 Umm... Sounds like your database is messed up to me. Do you have phpMyAdmin or something similar that will let you view the database? Find the column named 'id' and check its values.Database is fine, just tried it with normal links as oposed to select options, this passes the value ok. It must be related to using <option> somehow...Son Link to comment Share on other sites More sharing options...
son Posted August 2, 2008 Author Share Posted August 2, 2008 Database is fine, just tried it with normal links as oposed to select options, this passes the value ok. It must be related to using <option> somehow...SonHave it working now with:echo "<option value=\"{$row['id']}\">{$row['file_name']}</option>\n";Thanks for your help:-)Son Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 2, 2008 Share Posted August 2, 2008 I didn't think to look that close at the HTML, but that's a really weird bug...Glad it's working. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.