beansandsausages Posted February 22, 2008 Share Posted February 22, 2008 Hey all, i am trying to delete a row. Here is my code : if($_GET['action'] == "delete") { $id = $_POST['delete_id']; $sql = "DELETE FROM `news` WHERE id='{$id}' "; echo " <br /> <div class=\"textboxright\"> <h2><u>Delete Game Message ID : {$id}</u></h2> <p>Message Deleted ID : {$id} <br /> <a href=mem.php>back</a></p> </div>"; } the code {$id} echos the number 1 witch is correct its just not geting deleted from the db im well confused. Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/ Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 Well i would imagine it's because you're not actually a) connecting to MySQL b) selecting a database c) executing the query string or simply because id '1' doesn't exist Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473598 Share on other sites More sharing options...
beansandsausages Posted February 22, 2008 Author Share Posted February 22, 2008 i am connected that is just the revalent part every thing else works. i can post rest of code if you require Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473601 Share on other sites More sharing options...
fenway Posted February 22, 2008 Share Posted February 22, 2008 I'm going with ©. Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473607 Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 I'm going with c) too. Thus, please post the place in your code that you actually execute that SQL query. Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473613 Share on other sites More sharing options...
fenway Posted February 22, 2008 Share Posted February 22, 2008 I'm going with c) too. Thus, please post the place in your code that you actually execute that SQL query. And a mysql_error() call after that, just in case. Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473622 Share on other sites More sharing options...
beansandsausages Posted February 22, 2008 Author Share Posted February 22, 2008 This is the full code As messy as it is <?php if($_GET['action'] == "delete") { $id = $_POST['delete_id']; if($info[security] <= 7 ) { echo " no"; } else { $sql ="DELETE FROM `news` WHERE `id`='{$id}'"; echo " <br /> <div class=\"textboxright\"> <h2><u>Delete Game Message ID : {$id}</u></h2> <p>Message Deleted ID : {$id} <br /> <a href=mem.php>back</a></p> </div>"; } } // start of the game script MUST HAVE <h2> tag // game messages box if($game_show == "Y" ) { echo " <div class=\"textboxright\"> <h2><u>Game Messages</u></h2> "; $sql = "SELECT * FROM `news` ORDER BY id LIMIT 0,5"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "<p>No news posted. </div></p>"; include_once("layout_all/bottom.php"); exit; } while ($row = mysql_fetch_assoc($result)) { echo "<p> {$row["date"]} : {$row["time"]} : Poster {$row["poster"]} {$row["message"]} </p> <br /> "; if($info[security] >= 8 ) { echo "<p><form action=\"?action=delete\" method=\"POST\"><input type=\"hidden\" name=\"delete_id\" id=\"delete_id\" value=\"{$row['id']}\"><input type=\"submit\" value=\"Delete Post : {$row["id"]}\" > </form> <form action=\"mem.php?action=edit\" method=\"POST\"><input type=\"hidden\" name=\"edit_id\" id=\"edit_id\" value=\"{$row['id']}\"><input type=\"submit\" value=\"Edit Post : {$row["id"]}\" ></form></p> <br />"; } } mysql_free_result($result); echo " </div> <div class=\"clear\">"; } if($_GET['action'] == "showoff" ) { $update_gameshow = mysql_query("UPDATE `members` SET game_show='N' WHERE id='$info[id]'"); echo " Done "; } elseif($_GET['action'] == "showon" ) { $update_gameshow = mysql_query("UPDATE `members` SET game_show='Y' WHERE id='$info[id]'"); echo " Done"; } All works apart from this code if($_GET['action'] == "delete") { $id = $_POST['delete_id']; if($info[security] <= 7 ) { echo " no"; } else { $sql ="DELETE FROM `news` WHERE `id`='{$id}'"; echo " <br /> <div class=\"textboxright\"> <h2><u>Delete Game Message ID : {$id}</u></h2> <p>Message Deleted ID : {$id} <br /> <a href=mem.php>back</a></p> </div>"; } } but if echoed out {$id} are a id number so i dont know. Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473648 Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 Yeah I thought as much, option c) it is. you might consider doing this: mysql_query($sql); A string doesn't send itself to a query by magic Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473661 Share on other sites More sharing options...
beansandsausages Posted February 22, 2008 Author Share Posted February 22, 2008 Haha i cant see for looking. i had that but deleted it man im dumb. Thank you TOPIC SOLVED Link to comment https://forums.phpfreaks.com/topic/92429-stupid-delete-query/#findComment-473667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.