Truman Posted May 15, 2016 Share Posted May 15, 2016 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 More sharing options...
davej Posted May 15, 2016 Share Posted May 15, 2016 Obvious error here: if (empty($_POST[email'])) { Link to comment Share on other sites More sharing options...
Truman Posted May 15, 2016 Author Share Posted May 15, 2016 OK, I forgot one quotation but the topic is not about that. I am saying that I don't understand the distinguished code. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 15, 2016 Share Posted May 15, 2016 You are checking with if condition, that the variable is !$problem is not true I.E FALSE meaning no problems were detected so registration will complete, else if $problem equals TRUE you have problem, try again. 1 Link to comment Share on other sites More sharing options...
davej Posted May 15, 2016 Share Posted May 15, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now