www.webdeveloper.com
Results 1 to 3 of 3

Thread: PHP form validation

  1. #1
    Join Date
    Jun 2011
    Posts
    140

    PHP form validation

    I have a registration form on my site which looks and works great with hints on some of the fields when clicked in - http://tinyurl.com/7qh263p

    On displaying the form, it looks absolutely fine and when submitted correctly, the thank you message is also fine, but if a duplicate email address is entered and the error message displays, it cannot be read because my white background does not show and it is as if the script has just stopped loading, there is no footer, only header and black text with the error.

    It is this bit that generates the error:
    Code:
    //Select was OK - did it return anything?
        $rows = mysql_num_rows( $result );
    // if a row was found, the email has already been used.
        if ($rows > 0) {
          die("You have already registered with that e-mail address. Please click back on your browser to go back and try again.");
    
    // *****should Redisplay the page with error.....
    }
    How do I get the rest of my page to load so that the error can be read.

  2. #2
    Join Date
    May 2012
    Posts
    59
    I remember having this issue, so i built it into my framework.

    Try this though as a quick fix... seperate the header and footer html into header.php and footer.php...

    then when you want to kill the page, do this:

    Code:
    include("header.php");
    print "die message";
    include("footer.php");
    die();
    Hope that helps.

    Kind regards,
    Scott

  3. #3
    Join Date
    May 2012
    Posts
    42
    Using die() will halt the execution of the script. Nothing beyond that will be processed. Instead of using die() you could just store the error in a variable and echo it in your error box or where ever.
    PHP Code:
    <?php
    if ($rows 0) {
        
    $error_message "You have already registered with that e-mail address. Please click back on your browser to go back and try again.";
    }
    ?>

    <!-- later down in your HTML -->
    <div id="errorMessage"><?=$error_message?></div>

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