Created
April 28, 2021 06:56
-
-
Save vipul43/9e34034d38bae394b38ce4744756db34 to your computer and use it in GitHub Desktop.
template for hospital database project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<h1>Hospital</h1> | |
<form method="post"> | |
<input type="submit" name="addPatient" | |
class="button" value="add patient" /> | |
<input type="submit" name="showPatient" | |
class="button" value="show patient" /> | |
</form> | |
<?php | |
echo '<body style="background-color:#383A59; color:white">'; | |
if(array_key_exists('addPatient', $_POST)) { | |
addPatient(); | |
} | |
else if(array_key_exists('showPatient', $_POST)) { | |
showPatient(); | |
} | |
function addPatient() { | |
echo '<form method="post" action="adding_patient.php"> | |
ID: <input type="text" name="id"><br> | |
Name: <input type="text" name="name"><br> | |
Address: <input type="text" name="address"><br> | |
Contact: <input type="text" name="contact_number"><br> | |
Gender: <input type="text" name="gender"><br> | |
<input type="submit" value="commit"> | |
</form>'; | |
} | |
function showPatient() { | |
try { | |
$username = "root"; | |
$password = "password"; | |
$database = "hospital"; | |
$table = "patient"; | |
$mysqli = new mysqli("localhost", $username, $password, $database); | |
echo "<h2>PATIENT</h2><ol>"; | |
$query = "SELECT * FROM patient"; | |
$result = $mysqli->query($query); | |
echo '<table border="1" cellspacing="2" cellpadding="2"> | |
<tr> | |
<td> <font face="Monospace">Name</font> </td> | |
<td> <font face="Monospace">ID</font> </td> | |
<td> <font face="Monospace">Address</font> </td> | |
<td> <font face="Monospace">Contact Number</font> </td> | |
<td> <font face="Monospace">Gender</font> </td> | |
</tr>'; | |
while ($row = $result->fetch_assoc()) { | |
$field1name = $row["id"]; | |
$field2name = $row["name"]; | |
$field3name = $row["address"]; | |
$field4name = $row["contact_number"]; | |
$field5name = $row["gender"]; | |
echo '<tr> | |
<td> <font face="Monospace">'.$field1name.'</td> | |
<td> <font face="Monospace">'.$field2name.'</td> | |
<td> <font face="Monospace">'.$field3name.'</td> | |
<td> <font face="Monospace">'.$field4name.'</td> | |
<td> <font face="Monospace">'.$field5name.'</td> | |
</tr>'; | |
} | |
$result->free(); | |
echo "</ol>"; | |
} catch (mysqli_sql_exception $e) { | |
print "Error!: " . $e->getMessage() . "<br/>"; | |
die(); | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment