Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Q:empty()/redirect/include() ?

    empty($_post['submit']) this returns what for button "submit" non pressed / pressed ?
    empty($_post['firstname']) this returns what for firstname field equals "", " ", (novalue-and press submit) ?
    May use and isset() rather than empty() above, is the same ?
    how in php I redirect user to a specific page eg. retrieve.php ?
    How include files in html/xhtml and how on javascript just like
    php's include("file.html"); ?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    isset is not exactly related to empty.
    Isset is used to determine the existence of a variable, while empty is used to evaluate what that data includes.
    Empty is a boolean result set, so it will return either true or false, and since php is a loosely typecasted language, false == 0 and true != false.

    In your examples:
    empty($_POST['submit']) on a correct submit returns false
    empty($_POST['submit']) on a non-posted form returns true

    empty($_POST['firstName']) on a value of "" returns true
    empty($_POST['firstName']) on a value of " " returns false
    on a side note, the value "0" as a string is also considered empty.

    Isset is my recommendation for forms, and error checking is handled with empty and trim values.
    so
    PHP Code:
    if (isset($_POST['firstName']))

        
    $_POST['firstName'] = trim($_POST['firstName']);
        if (empty(
    $_POST['firstName']))
        {
            echo 
    'The value is empty, please enter the data.';
        }

    For example. As I mentioned, special cases need to be done for numbers, as "0" in a string is empty, and I have no idea why they decided to program that way.

    PHP redirects are done by adding headers to the request:
    header('Location: newpage.php');

    HTML and Javascript are not really equipped to handle includes on their own (i'm not an HTML specialist, but from my experience). You need to use a server side language to get the data you require. AJAX is a semi-inclusion method, but still relies on both a client and server process to initiate it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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