coklat12 Posted August 12, 2007 Share Posted August 12, 2007 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 More sharing options...
ballhogjoni Posted August 12, 2007 Share Posted August 12, 2007 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 More sharing options...
ballhogjoni Posted August 12, 2007 Share Posted August 12, 2007 make those changes for the wholepage of code. Link to comment https://forums.phpfreaks.com/topic/64480-php-with-html-problem/#findComment-321446 Share on other sites More sharing options...
coklat12 Posted August 12, 2007 Author Share Posted August 12, 2007 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 More sharing options...
ballhogjoni Posted August 12, 2007 Share Posted August 12, 2007 then there is somethingreally wrong with your logic. Link to comment https://forums.phpfreaks.com/topic/64480-php-with-html-problem/#findComment-321907 Share on other sites More sharing options...
teng84 Posted August 12, 2007 Share Posted August 12, 2007 instead of using strlen use isset i guess its better Link to comment https://forums.phpfreaks.com/topic/64480-php-with-html-problem/#findComment-321910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.