Jump to content

using $_GET


AL123

Recommended Posts

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]
  

Link to comment
https://forums.phpfreaks.com/topic/220481-using-_get/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/220481-using-_get/#findComment-1142308
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/220481-using-_get/#findComment-1142443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.