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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.