Xtremer360 Posted June 10, 2011 Share Posted June 10, 2011 I'm to the point where I want to just have someone scan over this and verify that my code has good syntax and the logic makes sense for each code block. And if not let me know so I can adjust it. <?php session_start(); // Start a new session // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submit'])) { $errors = "no"; if ((!isset($_POST['username']))||(empty($_POST['username']))||(trim($_POST['username'])=="")||(!isset($_POST['password']))||(empty($_POST['password']))||(trim($_POST['password'])=="")) { $errors = "yes"; $message = "The username and password fields were both left blank!"; } else { if ((!isset($_POST['username']))||(empty($_POST['username']))||(trim($_POST['username'])=="")) { $errors = "yes"; $message = "The username was left blank!"; } else { if ( preg_match("/^[^a-z]{1}|[^a-z0-9]+/i", $_POST['username']) ) { $errors = "yes"; $message = "The username contains invalid characters!"; } else { $username = strtolower($_POST['username']); } } if ((!isset($_POST['password']))||(empty($_POST['password']))||(trim($_POST['password'])=="")) { $errors = "yes"; $message = "The password was left blank!"; } } } //Output the result echo $message; ?> Quote Link to comment https://forums.phpfreaks.com/topic/239009-if-else-statements/ Share on other sites More sharing options...
ryanfilard Posted June 10, 2011 Share Posted June 10, 2011 It seems alright to me Quote Link to comment https://forums.phpfreaks.com/topic/239009-if-else-statements/#findComment-1228121 Share on other sites More sharing options...
requinix Posted June 10, 2011 Share Posted June 10, 2011 A few comments, all very minor: 1. For everything that isset() returns true, empty() also returns true. That means you only need to use empty() - using isset() as well is redundant. 2. You don't need a {1} in a regex. It's like saying "I have one single apple": because you said "one" the fact that you have a single apple is a given. In other words, also redundant. 3. PHP has booleans. Use them. $errors = false; $errors = true; 4. You've got a lot of parentheses. Not at the "too many" point, but you're getting close. Quote Link to comment https://forums.phpfreaks.com/topic/239009-if-else-statements/#findComment-1228128 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.