PartA:
Create the database. Name the database doctorWho. Then create a page that allows Doctor Who’s assistant to add a new patient record. You will need to give the assistant rights to this database. The assistant’s username is 'helper' and the password is 'feelBetter'. For this to work, you will need to create several pages so be sure to include all of them when submitting your work. Name the main page addPatient.php.
PartB:
Add at least five records to the patients table in the doctorWho database you created in PartA. Now create a page that will display three or more fields from each of these records. The display should consist of, at a minimum, the patient’s first and last names and a unique identifier. Name the page getPatient.php and be sure to include the necessary accompanying files when you submit your work.
Create database in phpMyadmin doctorWho
syntax: create database databasename;
create database doctorWho;
then use database
use doctorWho;
database doctorWho
Now create two tables
1) assistant table is stored login details of assistant
syntax: create table table_name (
col1 datatype,
col2 datatype,
....
);
create table assistant(
id int auto_increment,
username varchar(100);
password varchar(100),
primary key(id)
);
insert data in assistant table
syntax: insert into table_name (col1, col2, col3) values(val1, val2, val3);
insert into assistant values(1,'helper','feelBetter');
assistant table
2) patient table is stored patient details to submit add patient form
syntax: create table table_name (
col1 datatype,
col2 datatype,
....
);
create table patient(
id int auto_increment,
firstname varchar(100),
lastname varchar(100),
mobileno varchar(20),
primary key(id)
);
patient table insert data to submit add patient form
patient table
First create auth.php show assistant login form
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div style="margin-left:
30%;margin-top: 15%;">
<form action="auth_rights.php"
method="post"><!-- to click on submit button action tag goto
auth_rights.php -->
<div
class="col-md-6 text-center">
<h4>Assistant Login</h4>
<table class="table">
<tr>
<td><label>Username: </label></td>
<td><input class="form-control" type="text"
name="uname"></td><!-- enter username -->
</tr>
<tr>
<td><label>Password: </label></td>
<td><input class="form-control" type="password"
name="pass"></td><!-- enter password -->
</tr>
</table>
<div class="text-right">
<!-- submit button
-->
<input class="btn
btn-primary" type="submit" name="submit" value="Submit">
</div>
</div>
</form>
</div>
</div>
</body>
</html>
Assistant Login
click on submit button goes to file auth_rights.php
auth_rights.php
<?php
//database connction parameter
$hostname="localhost";
$username="root";
$password="root";
$database="doctorWho";
$db=mysqli_connect($hostname,$username,$password,$database);//call
mysqli_connect method for connection to database
if(!$db){
die('Connect Error==>'.mysqli_connect_error());
}
if(isset($_POST['submit'])) //check user click on
submit button
{
$uname = $_POST['uname']; //get
value
$pass = $_POST['pass']; //get
value
$sql_login = 'select * from
assistant where username = "'.trim($uname).'" and password =
"'.trim($pass).'";';//sql query for user is rights or not
$result =
mysqli_query($db,$sql_login);
$count =
mysqli_num_rows($result);//het count of rows in sql query
if($count == 1)
{
header('location:addPatient.php');//go to addPatient.php when user
login successfully
}
else
{
header('location:auth.php?login=Login Failed! Please Try
Again."');//go to same page auth.php when user enter worh username
and password
}
}
?>
after login sucessfully goto page addPatient.php show add patient form
addPatient.php
<!DOCTYPE html>
<html>
<head>
<title>Add Patient</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div style="margin-left:
5%;margin-top: 2%;">
<form class="form-inline"
action="save_data.php" method="post"><!-- to click on add
patient button action tag call save_data.php -->
<div
class="col-md-4">
<h4>Add Patient</h4>
<hr>
<div class="form-group">
<label>First
Name:</label>
<input class="form-control
ml-3" type="text" name="fname"><!-- enter first name
-->
</div>
<div class="form-group mt-3">
<label>Last
Name:</label>
<input class="form-control
ml-3" type="text" name="lname"><!-- enter last name
-->
</div>
<div class="form-group mt-3">
<label>Mobile
No:</label>
<input class="form-control
ml-3" type="text" name="mono"><!-- enter mobile no
-->
</div>
<div class="text-right mt-3">
<input class="btn
btn-primary mr-3" type="submit" name="submit" value="Save
Patient"><!-- button used for save patient details
-->
<a href="getPatient.php"
class="btn btn-info mr-3">Get Patient</a><!-- button
used for get datato alla patients -->
</div>
</div>
</form>
</div>
</div>
</body>
</html>
there are two buttons on add patient form
1) Save Patient button used to save patient details in database call save_data.php
2) Get Patient button used to get patient details in database call getPatient.php
save_data.php
<?php
//database connction parameter
$hostname="localhost";
$username="root";
$password="root";
$database="doctorWho";
$db=mysqli_connect($hostname,$username,$password,$database);//call
mysqli_connect method for connection to database
if(!$db){
die('Connect Error==>'.mysqli_connect_error());
}
if(isset($_POST['submit'])) //check user click on
submit button
{
$fname = $_POST['fname'];//get
value
$lname = $_POST['lname'];//get
value
$mobileno = $_POST['mono'];//get
value
$sql_insert = 'insert into patient
values("Null","'.$fname.'","'.$lname.'","'.$mobileno.'");';//sql
query for insert data in database
mysqli_query($db,$sql_insert);
header('location:addPatient.php?save=Patient save
sucessfully."');//call to same php addPatient.php user enter data
successfully
}
?>
save data sucessfully show the message in URL
getPatient.php
<?php
//database connction parameter
$hostname="localhost";
$username="root";
$password="root";
$database="doctorWho";
$db=mysqli_connect($hostname,$username,$password,$database);//call
mysqli_connect method for connection to database
if(!$db){
die('Connect Error==>'.mysqli_connect_error());
}
//create html table using echo in php to shoew all
patient data
echo "<table border='1px'
cellspacing='0'>";
echo "<tr><th>Unique
Id</th><th>First Name</th><th>Last
Name</th><th>Mobile No</th></tr>";
$sql_select = 'select * from
patient;';//sql query for get data in database
$result=
mysqli_query($db,$sql_select);
while($row =
mysqli_fetch_assoc($result)){
//bind the
patient data in UI table
echo
"<tr><td>".$row['id']."</td><td>".$row['firstname']."</td><td>".$row['lastname']."</td><td>".$row['mobileno']."</td></tr>";
}
echo "</table>";
?>
Show tables click on Get Patient button
==Please Upvote==
Get Answers For Free
Most questions answered within 1 hours.