AL123 Posted December 2, 2010 Share Posted December 2, 2010 I am a new programmer. I am working on a personal project for my portfolio, it is a simple blog. I am trying to give the user the ability to delete a blog entry. It works fine, the problem is that when you refresh the page, with out clicking 'delete' the entry is still deleted. $_GET is passing the $id to my function and it is executing. The code I have posted is my effort to fix the problem. How can I connect $_GET to the delete button ? I have tried using a hidden value but this is not working. Any help would be greatly appreciated. AL // code to display message before deletion if($_GET['T']) { echo("<div style='float:right; width:25%; height:100px; position:absolute; top:150px; right:15%;'>"); echo("<h2>Are you sure you want to delete:<h2>"); echo $_GET['T']; echo("<form method='get' action='?'>"); echo("<input type='submit' name='button' value='Delete'>"); echo("<input type='hidden' name='submit_check' value='1'>"); echo("</form>"); echo("<form action='http://nuke.industry.com/Blogspiracy/UserPage/index.php'>"); echo("<input type='submit' value='Cancel'/>"); echo("</form>"); echo("</div>"); } // code to delete a selected blog entry function delete_blog($id) { global $dbh; $sql = "DELETE FROM tblBlog WHERE tblBlog.id = '$id' LIMIT 1;"; $sth = $dbh->prepare($sql); $sth-> execute(); return; } if (isset($_GET['id']) && ($_GET['submit_check'])) how do I "GET" the hidden value? { $remove = delete_blog($_GET['id']); } [code] Quote Link to comment https://forums.phpfreaks.com/topic/220481-using-_get/ Share on other sites More sharing options...
AbraCadaver Posted December 2, 2010 Share Posted December 2, 2010 First, you should never use the get method for anything other than retrieving (getting). To add/modify/delete, etc. use post. Second, you should probably post to another page that does the delete and that page will redirect back to where you want the user to be. Quote Link to comment https://forums.phpfreaks.com/topic/220481-using-_get/#findComment-1142308 Share on other sites More sharing options...
AL123 Posted December 2, 2010 Author Share Posted December 2, 2010 OK, I will have time to work on this later today. I will come up with something that uses only post and see what happens,ether way I will show my results. Thanks, AL Quote Link to comment https://forums.phpfreaks.com/topic/220481-using-_get/#findComment-1142312 Share on other sites More sharing options...
AL123 Posted December 3, 2010 Author Share Posted December 3, 2010 I figured out a hack/solution that works using $_POST. It's not pretty but it works for now. Thanks AbraCadaver for steering me in the right direction. AL function delete_blog($title) { global $dbh; $sql = "DELETE FROM tblBlog WHERE tblBlog.Title = '$title' LIMIT 1;"; $sth = $dbh->prepare($sql); $sth-> execute(); return; } if (isset($_POST['selectedDelete'])) { $title = $_POST['selectedDelete']; $remove = delete_blog($title); } <div style="float:right; width:25%; height:100px; position:absolute; top:80px; right:15%;"> <h2>Type the Blog title you would like to delete.<h2> <form method='post' action='?'> <INPUT TYPE="text" NAME="selectedDelete"> <input type='submit' name='button' value='Delete'> </form> <p>Return to your Home Page</p> <form action='http://nuke.industry.com/Blogspiracy/UserPage/index.php'> <input type='submit' value='OK'> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/220481-using-_get/#findComment-1142443 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.