summary refs log tree commit diff stats
path: root/mysql-php/code/a1.php
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-02-03 16:29:27 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-02-03 16:29:27 +0000
commite031215516573b14545e81665b991176a467bce5 (patch)
treec35521ae8c4b22cff29bb58f633a639541ca99d2 /mysql-php/code/a1.php
parent15ff931b72b24a8f7f1d06d0549d985162a1d6b6 (diff)
downloadzadania-e031215516573b14545e81665b991176a467bce5.tar.gz
Implement PHP assignment #3, improve the rest
Diffstat (limited to 'mysql-php/code/a1.php')
-rw-r--r--mysql-php/code/a1.php24
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>';