Reputation: 5027
I have an <a href>
in my webpage that has the following link:
<a href=\"?remove=0\">Remove</a>
Which is fine. I then reference it by the following:
if(isset($_REQUEST['remove']))
To check if it was set and then perform the relative actions (removing the value from array).
BUT, when I click ANOTHER form in my php page, which is set to method='POST'
, The $_GET
value stays in the URL bar and so therefore for some reason is passed again and is ruining my program.
Any thoughts?
Upvotes: 0
Views: 43
Reputation: 8198
Removing sounds like a dangerous operation. It shouldn't be performed in response to a GET request: a user might reload the page, accidentally removing something again, or a searching robot might follow that link and remove that something (assuming, of course, it has permissions to). Even browsers nowadays do prefetching - what happens if one of the prefetched links is the remove link?
So, it would be wise to check
if (isset($_POST['remove']))
and convert the link to remove to a form.
Upvotes: 0
Reputation: 7157
It sounds like you are missing an action=
prop in your form. If you don't specify where the form should post to, it posts to the current URL, query string included.
Posts to current URL:
<form method="post">
Posts to URL you specify:
<form method="post" action="mypage.php">
Upvotes: 5