As the question asks, How do I unset POST values? Is there a way it can be done?
unset($_POST['value']);
It’s just another array
Cheers thanks for the confirmation. I have tried that, so obviously there must be something else wrong within my code.
Thanks spike for the quick response too.
N/P
What is it that you are trying to do?
I have some conditional includes:
<?php
if (isset($_POST['createCompany'])) {
include('companyForm.php');
} elseif (isset($_POST['companyListed'])) {
include('createClient.php');
} else {
include('newAdvertiserStep1.php');
}
?>
Basically the default page has the option within a drop-down on the page to allow a user to select whether they have already regd their company with me.
If a user clicks ‘submit’ (which is $_POST[‘companyListed’]) without selecting one of the companies within the list, then at the top of the createClient.php page I have this:
if (isset($_POST['companyListed'])) {
if (empty($_POST['companyId'])) {
$_SESSION['err'] = "<span class='error'>You need to select a company!</span><br />";
unset($_POST['companyListed']);
header("Location: newAdvertiser.php");
exit();
} else {
$companyId = $_POST['companyId'];
}
} else {
$_SESSION['err'] = "<span class='error'>You are not authorised to enter this part of the site, please try again!</span><br />";
header("Location: index.php");
exit();
}
But when I test it - it redirects, but does not include the default page (to which I thought it would have as I unset the initial post var.
Hope this makes sense?
You do not need to unset the POST var as they are not maintained across requests. That is, if you use header(), you are essentially creating a new request so the previous POSTs would not be sent with it.
One thing I see is:
include(‘newAdvertiserStep1.php’);
and
header(“Location: newAdvertiser.php”);
From what I understand from your post, this is the default page for a user to go to if they are not registered with you… these are different URLs, is this correct?
Thanks for that info, I wasn’t aware of that, but I am now - cheers
The
include(‘newAdvertiserStep1.php’);
is actually a conditional include contained within the main page of newAdvertiser.php.
I did try to redirect to newAd…Step1.php but to no avail either.
When I try the redirect to newAdvertiser, the section where the conditional include is suppose to be is not there, but within that main page, I then click on a link to ‘newAdvertiser.php’ and the page displays correctly WITH the $_SESSION[‘err’] echoed.
So you mean, when you redirect to newAdvertiser, it doesn’t work, but if you click a link to newAdvertiser, it does work? Does the link submit a form? What happens if you put newAdvertiser.php in the address bar?
That is correct.
Spot on!
Yes it does.
My sincere thanks for your helps old_iron and spike, however, I think I have resolved the problem as I was trying to review the code. I was placing this code:
if (isset($_POST['companyListed'])) {
if (empty($_POST['companyId'])) {
$_SESSION['err'] = "<span class='error'>You need to select a company!</span><br />";
unset($_POST['companyListed']);
header("Location: newAdvertiser.php");
exit();
} else {
$companyId = $_POST['companyId'];
}
} else {
$_SESSION['err'] = "<span class='error'>You are not authorised to enter this part of the site, please try again!</span><br />";
header("Location: index.php");
exit();
}
?>
within the includes of the condition which is half-way through my script, and I believe it is a case that headers cannot be sent after any html code has been sent back. I placed this code at the top of the newAdvertiser.php page (mainPage) and it works fine.
Again, many thanks for your assistance in the matter.
I’m glad you’ve fixed it - the reason I asked if the link submitted a form, because that way the POST vars ARE sent - whereas if you use header(), they are not.
I think it was your initial assumption that POSTs were sent with header() that caused the problem (since you wanted to unset them) - either way, glad it’s fixed now.
Also glad you got it working BJ and thanks old iron :tup:
No problem SpikeZ - sorry for hijacking your responses