SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Florida
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does this happen?

    Hello everyone:

    Once again, I am working on learning PHP. I have done very well, but there is something I need help with.

    The script I am working for deals with registering usernames and passwords. That isn't the problem. The problem is, when I call the page the form is on, it is already showing that I forgot to enter my password before I fill in one field, and it tells me to try again, which is the message the visitor should receive if they were unsuccessful (the page can be found at: http://iwdtestsite.com/phpmysql3/register2.php if you need to see what I am talking about)

    I hate putting the entire script on, but I really would not know where to snip at.

    PHP Code:
    <?php # Script 3.13 - register.php

        
    if (isset($_POST['submit'])) {
            
    // validate the form
        
        
    $message NULL;
            
            if(
    strlen($_POST['name']) > 0) {
                
    $name TRUE;
            } else {
                
    $name FALSE;
                
    $message .= '<p>You forgot to enter your name!</p>';
            }
        
            if (
    strlen($_POST['email']) > 0) {
                
    $name TRUE;
            } else {
                
    $name FALSE;
                    
    $message .= '<p>You forgot to enter your email address!</p>';
            }
            
            if (
    strlen($_POST['username']) > 0) {
                
    $username TRUE;
            } else {
                
    $username FALSE;
                    
    $message .= '<p>You forgot to enter your username!</p>';
            
            }
            
            if (
    strlen ($_POST['password1']) > 0) {
                
    $password TRUE;
            } else {
                
    $password FALSE;
                    
    $message .= '<p>Your password did not match the confirmed password!</p>';
            }
            } else {
                
    $password FALSE;
                    
    $message .= '<p>You forgot to enter your password!</p>';
            }
            if (
    $name && $email && $username && $password) {
            
    // If everything's okayOKs. Register the user.
            
            // Send an email.
            
                
    $body "Thank you for registering with our site!\nYour username {$_POST['username']}'    
                    and your password is '
    {$_POST['password1']}'.\n\nSincerely,\nAdministration";
                
    mail($_POST['email'], 'Thank you for registering!'$body'From: [email]info@iwdtestsite.com[/email]');
                
                
    header('Location: thankyou.php');
                exit();
            
            } else {
                
    $message .= '<p>Please try again.</p>';
            }
        
        
    // Set the page title and include the HTML header.
        
            
    $page_title 'Register!';
                include(
    './header.inc');
                
            
    // Print the error message if there is one.
        
            
    if (isset($message)) {
                echo 
    '<font color="red">'$message,  '</font>';
                }
            
    ?>
    <form action"<?php echo $_SERVER['PHP_SELF']; ?> method="post">

    <fieldset>

      <legend>Enter your information in the form below (<font color="#FF0000">* Required</font>):</legend>

      <p><b><font color="#FF0000">*</font>Name:</b> 
        <input type="text" name="name" size="20" maxlength="40" /></p>

      <p><b><font color="#FF0000">*</font>Email Address:</b> 
        <input type="text" name="email" size="20" maxlength="60" />
      </p>

      <p><b><font color="#FF0000">*</font>User Name:</b> 
        <input type="text" name="username" size="20" maxlength="40" />
      </p>

      <p><b><font color="#FF0000">*</font>Password:</b> 
        <input type="password" name="password1" size="20" maxlength="40" />
      </p>

      <p><b><font color="#FF0000">*</font>Confirm Password:</b> 
        <input type="password" name="password2" size="20" maxlength="40" />
      </p>

    </fieldset>

    <div align="center"><input type="submit" name="submit" value="Submit Information" /></div>

    </form>

    <?php
    // Complete the conditional and PHP page.

         // End of the main SUBMIT conditional
        
            
    include ('./footer.inc');
    ?>
    I am unconcerned with the warnings for the header.inc and footer.inc as I have not created those yet.

    Thank you in advance for an help you can give.

    Magikey

  2. #2
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have an issue with your braces.

    Look at

    PHP Code:
      if (strlen ($_POST['password1']) > 0) {
                
    $password TRUE;
            } else {
                
    $password FALSE;
                    
    $message .= '<p>Your password did not match the confirmed password!</p>';
            }
            } else {
                
    $password FALSE;
                    
    $message .= '<p>You forgot to enter your password!</p>';
            } 
    That section, and you'll notice that you have two closing braces before 'else'.

    Change it to this:

    PHP Code:
    <?php # Script 3.13 - register.php

        
    if (isset($_POST['submit'])) {
            
    // validate the form
        
        
    $message NULL;
            
            if(
    strlen($_POST['name']) > 0) {
                
    $name TRUE;
            } else {
                
    $name FALSE;
                
    $message .= '<p>You forgot to enter your name!</p>';
            }
        
            if (
    strlen($_POST['email']) > 0) {
                
    $name TRUE;
            } else {
                
    $name FALSE;
                    
    $message .= '<p>You forgot to enter your email address!</p>';
            }
            
            if (
    strlen($_POST['username']) > 0) {
                
    $username TRUE;
            } else {
                
    $username FALSE;
                    
    $message .= '<p>You forgot to enter your username!</p>';
            
            }
            
            if (
    strlen ($_POST['password1']) > 0) {
                
    $password TRUE;
            } else {
                
    $password FALSE;
                    
    $message .= '<p>Your password did not match the confirmed password!</p>';
            } else {
                
    $password FALSE;
                    
    $message .= '<p>You forgot to enter your password!</p>';
            }
            if (
    $name && $email && $username && $password) {
            
    // If everything's okayOKs. Register the user.
            
            // Send an email.
            
                
    $body "Thank you for registering with our site!\nYour username {$_POST['username']}'    
                    and your password is '
    {$_POST['password1']}'.\n\nSincerely,\nAdministration";
                
    mail($_POST['email'], 'Thank you for registering!'$body'From: [email]info@iwdtestsite.com[/email]');
                
                
    header('Location: thankyou.php');
                exit();
            
            } else {
                
    $message .= '<p>Please try again.</p>';
            }
        
        
    // Set the page title and include the HTML header.
        
            
    $page_title 'Register!';
                include(
    './header.inc');
                
            
    // Print the error message if there is one.
        
            
    if (isset($message)) {
                echo 
    '<font color="red">'$message,  '</font>';
                }
            
    ?>
    <form action"<?php echo $_SERVER['PHP_SELF']; ?> method="post">

    <fieldset>

      <legend>Enter your information in the form below (<font color="#FF0000">* Required</font>):</legend>

      <p><b><font color="#FF0000">*</font>Name:</b>
        <input type="text" name="name" size="20" maxlength="40" /></p>

      <p><b><font color="#FF0000">*</font>Email Address:</b>
        <input type="text" name="email" size="20" maxlength="60" />
      </p>

      <p><b><font color="#FF0000">*</font>User Name:</b>
        <input type="text" name="username" size="20" maxlength="40" />
      </p>

      <p><b><font color="#FF0000">*</font>Password:</b>
        <input type="password" name="password1" size="20" maxlength="40" />
      </p>

      <p><b><font color="#FF0000">*</font>Confirm Password:</b>
        <input type="password" name="password2" size="20" maxlength="40" />
      </p>

    </fieldset>

    <div align="center"><input type="submit" name="submit" value="Submit Information" /></div>

    </form>

    <?php
    // Complete the conditional and PHP page.

         // End of the main SUBMIT conditional
        
            
    include ('./footer.inc');
    ?>
    Ryan

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Florida
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. I tried taking the extra brace out, but now I get a parser error on that line.

  4. #4
    public static void brain Gybbyl's Avatar
    Join Date
    Jun 2002
    Location
    Montana, USA
    Posts
    647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, you know what, as opposed to taking out that brace, change it to this:

    PHP Code:
    if (strlen ($_POST['password1']) > 0) {
        
    $password TRUE;
    } else {
        
    $password FALSE;
        
    $message .= '<p>You forgot to enter your password!</p>';

    Ryan

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    Florida
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did as you said, but it is still showing You forgot to enter your password! and Please try again.


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
  •