SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I unset POST values?

    As the question asks, How do I unset POST values? Is there a way it can be done?
    Regards,
    BJ Duncan

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    unset($_POST['value']); 
    It's just another array
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Regards,
    BJ Duncan

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    N/P

    What is it that you are trying to do?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have some conditional includes:
    PHP Code:
     <?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:
    PHP 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();

    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?
    Regards,
    BJ Duncan

  6. #6
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  7. #7
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by old_iron View Post
    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.
    Thanks for that info, I wasn't aware of that, but I am now - cheers

    Quote Originally Posted by old_iron View Post
    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?
    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.
    Regards,
    BJ Duncan

  8. #8
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BJ Duncan View Post
    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?

  9. #9
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by old_iron View Post
    So you mean, when you redirect to newAdvertiser, it doesn't work?
    That is correct.

    Quote Originally Posted by old_iron View Post
    but if you click a link to newAdvertiser, it does work?
    Spot on!

    Quote Originally Posted by old_iron View Post
    Does the link submit a form?
    Yes it does.

    Edit:


    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:
    PHP 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.
    Regards,
    BJ Duncan

  10. #10
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Also glad you got it working BJ and thanks old iron
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem SpikeZ - sorry for hijacking your responses


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •