Display error - Help needed

Discussion in 'PHP' started by PowerExtreme, Mar 19, 2008.

  1. #1
    
    //Check if the forms are blank
    if(($myusername=="") || ($mypassword=="")){
    
    header("Location:index.php");
    }else{
    
    }
    
    PHP:
    My problem is, when one of the forms are blank, how would i display and error message on the homepage? cookies?sessions? is there any other options besides those? because they get messy... not to mention that i also have to unset after..

    thx
     
    PowerExtreme, Mar 19, 2008 IP
  2. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can pass a parameter to your index.php in the location line, for example:
    header("Location: index.php?error=1");

    and in the index file just check for it:
    if (isset($_GET['error']))
    {
    echo 'one of the fields is blank';
    }
     
    mulari, Mar 19, 2008 IP
  3. Gordaen

    Gordaen Peon

    Messages:
    277
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What mulari suggested is the quickest, easiest way of doing it. A slightly more involved but useful method to consider is using "flash data." Essentially, it is data stored in the session only until the next request and is very typical for errors or status update (e.g., "Record X deleted").
     
    Gordaen, Mar 19, 2008 IP