Jump to content

Recommended Posts

hi i'm new here.. i have a problem with this code .. there's nothing appear in the browser . the form is works but when i combine it with conditional statement something goes wrong .anybody help me please..

 

<?php 
if (isset($_POST['submit'])) {     // Handle the form.
       // Check for a name.
       if (strlen($_POST['name']) > 0)
          $name = TRUE;
       else{
          $name = FALSE;
          echo '<p>You forgot to enter yor name!</p>';
       }

       //Check for an email address
       if (strlen($_POST['email']) > 0)
          $email = TRUE;
       else{
          $email = FALSE;
           echo '<p>You forgot to enter your email address!</p>';
       }

       //Check for username
       if (strlen($_POST['username']) > 0)
          $username = TRUE;
       else{
          $username = FALSE;
          echo '<p>You forgot to enter your username!</p>';
       }

       //check for password and match against then confirmed password.
       if (strlen($_POST['password1']) > 0){
          if ($_POST['password1'] == $_POST['password2'])
              $password = TRUE;
  else{
      $password = FALSE;
      echo '<p>Your password did not match the confirmed password!</p>';
`      	      }
       }
       else {
              $password = FALSE;
              echo '<p>Your forgot your password!</p>';
            }
      
       
       if ($name && $email && $username && $password) // If everything's okay.
   //Register the user.
   echo '<p>You are now registered.</p>';
       else
   //Something's not TRUE.
           echo '<p>Please go back and try again.</p>';
              
} else { //Display the form.

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>Name:</b><input type="text" name="name" size="20" maxlength="40"/></p>
<p><b>Email Address:</b><input type="text" name="email" size="40" maxlength="60" /></p>
<p><b>User Name:</b><input type="text" name="username" size="20" maxlength="40" /></p>
<p><b>Password:</b><input type="password" name="password1" size="20" maxlength="40"/></P>
<p><b>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><!--End of Form-->


<?php}//END THE MAIN CONDITION HERE

Link to comment
https://forums.phpfreaks.com/topic/64480-php-with-html-problem/
Share on other sites

You forgot to add a } before the else clause. Every if else statement should look like if () { //somecode } else { // somecode }

if (strlen($_POST['name']) > 0)
          $name = TRUE;
       }else{
          $name = FALSE;
          echo '<p>You forgot to enter yor name!</p>';
       }

       //Check for an email address
       if (strlen($_POST['email']) > 0)
          $email = TRUE;
       }else{
          $email = FALSE;
           echo '<p>You forgot to enter your email address!</p>';
       }

Link to comment
https://forums.phpfreaks.com/topic/64480-php-with-html-problem/#findComment-321445
Share on other sites

make those changes for the wholepage of code.

 

:( still won't work.. nothing appear in the browser

 

<!--Register-->
<?php 
if (isset($_POST['submit'])) 
{// Handle the form.

       // Check for a name.
       if (strlen($_POST['name']) > 0)
       {
          $name = TRUE;
       }
       else
       {
          $name = FALSE;
          echo '<p>You forgot to enter yor name!</p>';
       }


       //Check for an email address
       if (strlen($_POST['email']) > 0)
       {
          $email = TRUE;
       }
       else
       {
          $email = FALSE;
          echo '<p>You forgot to enter your email address!</p>';
       }



       //Check for username
       if (strlen($_POST['username']) > 0)
       {
          $username = TRUE;
       }
       else
       {
          $username = FALSE;
          echo '<p>You forgot to enter your username!</p>';
       }



       //check for password and match against then confirmed password.
       if (strlen($_POST['password1']) > 0)
       {
          if ($_POST['password1'] == $_POST['password2'])
          {
              $password = TRUE;
          }
  else
          {
      $password = FALSE;
      echo '<p>Your password did not match the confirmed password!</p>';
`      	  }
       }
       else 
       {
              $password = FALSE;
              echo '<p>Your forgot your password!</p>';
       }
      
       // If everything's okay.
       if ($name && $email && $username && $password)
       {
   //Register the user.
   echo '<p>You are now registered.</p>';
       }
       else
       {
   //Something's not TRUE.
           echo '<p>Please go back and try again.</p>';
       }
              
} else { //Display the form.
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>Name:</b><input type="text" name="name" size="20" maxlength="40"/></p>
<p><b>Email Address:</b><input type="text" name="email" size="40" maxlength="60" /></p>
<p><b>User Name:</b><input type="text" name="username" size="20" maxlength="40" /></p>
<p><b>Password:</b><input type="password" name="password1" size="20" maxlength="40"/></P>
<p><b>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>
<!--End of Form-->


<?php}//END THE MAIN CONDITION HERE

Link to comment
https://forums.phpfreaks.com/topic/64480-php-with-html-problem/#findComment-321457
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.