From a5afdcfa7165e100042f03de1b3f7a601389776f Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Wed, 24 Jan 2024 17:16:15 +0000 Subject: Rewrite PHP assignment #1 mysql-php/code/a1.php: Perform some syntactic and structural changes. --- mysql-php/code/a1.php | 64 ++++++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 42 deletions(-) diff --git a/mysql-php/code/a1.php b/mysql-php/code/a1.php index 107f07a..4569ca8 100644 --- a/mysql-php/code/a1.php +++ b/mysql-php/code/a1.php @@ -59,6 +59,7 @@ function display_menu() { function display_search_form() { html_prologue('Student details'); + /* $_SERVER['PHP_SELF'] is approximately equal to $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO'] */ ?>

Enter E-mail address to search for the record of a student

@@ -117,21 +118,12 @@ function insert_details($dbh) { 'city' => 'City', 'roll' => 'Roll No.' ]); - $stmt = mysqli_prepare($dbh, 'INSERT INTO STUDENT ( - ROLL, NAME, EMAIL, CITY, DATE_OF_BIRTH - ) VALUES (?,?,?,?,?)'); - mysqli_stmt_execute($stmt, [ - $vars['roll'], $vars['name'], $vars['email'], $vars['city'], - $vars['date_of_birth'] - ]); + $stmt = mysqli_prepare($dbh, 'INSERT INTO STUDENT (ROLL, NAME, EMAIL, CITY, DATE_OF_BIRTH) VALUES (?,?,?,?,?)'); + mysqli_stmt_bind_param($stmt, 'sssss', $vars['roll'], $vars['name'], $vars['email'], $vars['city'], $vars['date_of_birth']); + mysqli_stmt_execute($stmt); } -function show_table($dbh) { - $result = mysqli_query($dbh, 'SELECT * FROM STUDENT'); - html_prologue('Students\' details'); - ?> -

Students' details

-

record(s) found.

+function show_table($result) { ?> @@ -139,48 +131,36 @@ function show_table($dbh) { - + + - +
Roll No.E-mail City Date of birth
- ', array_map('htmlspecialchars', [ - $row['ROLL'], $row['NAME'], $row['EMAIL'], $row['CITY'], - $row['DATE_OF_BIRTH'] - ])); ?> + ', array_map('htmlspecialchars', [$row['ROLL'], $row['NAME'], $row['EMAIL'], $row['CITY'], $row['DATE_OF_BIRTH']])); ?>
+ +

Students' details

+

record(s) found.

Students' details

The students who were born in years 2000 to 2005, inclusive.

record(s) found.

- - - - - - - - - - -
Roll No.NameE-mailCityDate of birth
- ', array_map('htmlspecialchars', [ - $row['ROLL'], $row['NAME'], $row['EMAIL'], $row['CITY'], - $row['DATE_OF_BIRTH'] - ])); ?> -