dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: if statment wont work

  1. #1
    Join Date
    Nov 2006
    Posts
    47

    if statment wont work

    PHP Code:
    <?php
    if(isset($_POST['action'])){
        
    header("register.php");
    }
    ?>
    for some reason the if statement won't work
    it work when i set a variable but i doesnt work it super globals variable

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,296
    It looks OK as far as syntax. If you're not getting the desired result, then probably $_POST['action'] is not being set the way you think it should be, or there is a spelling mismatch (for instance, if the form element is named "Action" instead of "action"). You might want to debug by adding the following lines somewhere to see what values were actually passed to the script:
    PHP Code:
    echo "<pre>";
    print_r($_POST);
    echo 
    "</pre>\n"
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Nov 2006
    Posts
    41
    isset, empty, etc...

  4. #4
    Join Date
    Nov 2006
    Posts
    197
    Normally I would write that as:

    Code:
    if (isset($_POST['action'])) {
    	if($_POST['action'] == 'whatever') {
    		header("register.php");
    	}
    }
    
    //Where "whatever" comes from the submit button (for example):
    
    <input type="submit" name="action" value="whatever">
    Also HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. I dunno if that's the issue here or not.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles