public static function run() { if ($_SERVER["REQUEST_METHOD"] == "POST") { $new_post = $_POST; if (isset($_FILES["submissionFile"])) { $new_post["submissionFile"] = $_FILES["submissionFile"]; } $submission = new Submission($new_post); if ($submission->getErrorCount() != 0) { SubmissionView::show($submission); } else { $user = UsersDB::getUserBy('userName', $submission->getUserName()); if ($user != null) { HomeView::show($user); } else { $submission->setError('userName', 'USER_NAME_DOES_NOT_EXIST'); SubmissionView::show($submission); } } } else { // Initial link SubmissionView::show(null); } }
$invalidUser = new User(array("userName" => "krobbins\$")); $userId = UsersDB::addUser($invalidUser); echo "Number of users in db after added is: " . count(UsersDB::getAllUsers()) . "<br>"; echo "User ID of new user is: {$userId}<br>"; ?> <h2>It should get a User by userName</h2> <?php $user = UsersDB::getUserBy('userName', 'George'); echo "The value of User George is:<br>{$user}<br>"; ?> <h2>It should get a User by userId</h2> <?php $user = UsersDB::getUserBy('userId', '3'); echo "The value of User 3 is:<br>{$user}<br>"; ?> <h2>It should not get a User not in Users</h2> <?php $user = UsersDB::getUserBy('userName', 'Alfred'); echo "The value of User Alfred is:<br>{$user}<br>"; ?> <h2>It should not get a User by a field that isn't there</h2> <?php $user = UsersDB::getUserBy('telephone', '21052348234'); echo "The value of User with a specified telephone number is:<br>{$user}<br>"; ?> </body> </html>