diff options
Diffstat (limited to 'mysql-php/code/a1.php')
-rw-r--r-- | mysql-php/code/a1.php | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/mysql-php/code/a1.php b/mysql-php/code/a1.php index 4569ca8..614f044 100644 --- a/mysql-php/code/a1.php +++ b/mysql-php/code/a1.php @@ -1,7 +1,7 @@ <?php declare(strict_types=1); error_reporting(E_ALL); -// student: name roll city email date_of_birth + function connect_to_database() { mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); if (!($dbh = mysqli_connect('localhost', 'root', ''))) @@ -103,7 +103,7 @@ function display_failure($reason) { function check_post_vars($vardesc) { $vars = []; foreach ($vardesc as $name => $desc) { - if (!isset($_POST[$name]) || empty($_POST[$name])) + if (empty($_POST[$name])) display_failure('The ' . $desc . ' field can not be empty'); $vars[$name] = $_POST[$name]; } @@ -186,7 +186,7 @@ function show_record($record) { <?php } -if (!isset($_SERVER['PATH_INFO']) || empty($_SERVER['PATH_INFO']) || $_SERVER['PATH_INFO'] == '/') { +if (empty($_SERVER['PATH_INFO']) || $_SERVER['PATH_INFO'] == '/') { display_menu(); die(); } @@ -211,17 +211,17 @@ if ($path === 'insert') { show_table_dob_range($dbh); mysqli_close($dbh); } elseif ($path === 'search') { - if (isset($_GET['email']) && !empty($_GET['email'])) { - $dbh = connect_to_database(); - if (!($record = search_student($dbh, $_GET['email']))) { - mysqli_close($dbh); - display_failure('Record not found for given E-mail: ' . htmlspecialchars($_GET['email'])); - } - show_record($record); - mysqli_close($dbh); - } else { + if (empty($_GET['email'])) { display_search_form(); + die(); } + $dbh = connect_to_database(); + if (!($record = search_student($dbh, $_GET['email']))) { + mysqli_close($dbh); + display_failure('Record not found for given E-mail: ' . htmlspecialchars($_GET['email'])); + } + show_record($record); + mysqli_close($dbh); } else { display_menu(); echo '<p class="error">Path <code>' . htmlspecialchars($path) . '</code> was not found.</p>'; |