Jump to content

Not understanding if-else statement


Truman

Recommended Posts

I'm working of registration form and I have a problem with understanding one of the codes.

<?php // Script 8.9 - register.php
define ('DEFINE', 'register');
include('templates/header.html');
print '<h2>Registration Form</h2>
  <p>Register so that you can take advantage of certain features like this, that, and the other things</p>';
print '<style type="text/css" media="screen">
  .error { color: red; }
 </style>';
 if ($_SERVER['REQUESTED_METHOD'] == 'POST') {
    $problem = FALSE;
	if (empty($_POST['first_name'])) {
	   $problem = TRUE;
	   print '<p class="error">Please enter your first name!</p>';
	}
    if (empty($_POST['last_name'])) {
	   $problem = TRUE;
	   print '<p class="error">Please enter your last name!</p>';
	   }
	if (empty($_POST[email'])) {
	   $problem = TRUE;
	   print '<p class="error">Please enter your email address.</p>';
	   }
    if (empty($_POST['password1'])) {
	   $problem = TRUE;
	   print '<p class="error">Please enter a password.</p>';
	}	 
    if ($_POST['password1'] != $_POST['password2'])	 {
	   $problem = TRUE;
	   print '<p class="error">Your password did not match your confirm password.</p>';
	}
	if (!$problem) {
	print '<p>You are now registered.</p>'
	}
	$_POST = array();
} else {
	print '<p class="error">Please try again!</p>
   }
}
?>

this part:

if (!$problem) {
	print '<p>You are now registered.</p>'
	}

Why are we using exclamation mark here? I already defined $problem = FALSE at the beginning of the whole code. That means that there is no problem. If we reverse it to TRUE it will mean that there is a problem with registration but in that case the user shouldn't see "You are now registered". The if condition is fulfilled in any case because with don't have any '<', '>' or '=='.

Link to comment
Share on other sites

So you didn't write this code and you don't understand it? It seems to put a style block in the middle of the html, which is illegal. The style block should go inside the file head. The ! is the logical negation operator in Php and most modern languages.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...