Jump to content

php with html problem


coklat12

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.