Skip to content

Instantly share code, notes, and snippets.

@GurunadhPachappagari
Last active April 28, 2021 15:04
Show Gist options
  • Select an option

  • Save GurunadhPachappagari/12604b9741021ff58eb26ae9b1a6f335 to your computer and use it in GitHub Desktop.

Select an option

Save GurunadhPachappagari/12604b9741021ff58eb26ae9b1a6f335 to your computer and use it in GitHub Desktop.
<html>
<body>
<?php
echo '<body style="background-color:#383A59; color:white">';
$PATIENTID=$_POST["id"];
$PATIENTNAME=$_POST["name"];
$PATIENTADDRESS=$_POST["address"];
$PATIENTCONTACT=$_POST["contact_number"];
$PATIENTGENDER=$_POST["gender"];
try {
$username = "root";
$password = "guru";
$database = "hospital";
$table = "emergency_patient";
$mysqli = new mysqli("localhost", $username, $password, $database);
$query = "INSERT INTO emergency_patient (id, name, address, contact_number, gender) VALUES ('$PATIENTID', '$PATIENTNAME', '$PATIENTADDRESS', '$PATIENTCONTACT', '$PATIENTGENDER')";
$result = $mysqli->query($query);
if ($result == 1){
echo "successfully added<br>";
echo "$PATIENTID<br>";
echo "$PATIENTNAME<br>";
echo "$PATIENTADDRESS<br>";
echo "$PATIENTCONTACT<br>";
echo "$PATIENTGENDER<br>";
echo '<form method="post" action="emergency_patient.php">
<input type="submit" value="go back">
</form>';
} else {
echo "FAILED TO ADD DATA<br>";
}
} catch (mysqli_sql_exception $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</body>
</html>
<html>
<body>
<?php
echo '<body style="background-color:#383A59; color:white">';
$PATIENTID=$_POST["id"];
try {
$username = "root";
$password = "guru";
$database = "hospital";
$table = "emergency_patient";
$mysqli = new mysqli("localhost", $username, $password, $database);
$query = "delete from emergency_patient where id = '$PATIENTID'";
$result = $mysqli->query($query);
if ($result == 1){
echo "successfully deleted<br>";
echo "$PATIENTID<br>";
echo "$PATIENTNAME<br>";
echo "$PATIENTADDRESS<br>";
echo "$PATIENTCONTACT<br>";
echo "$PATIENTGENDER<br>";
echo '<form method="post" action="emergency_patient.php">
<input type="submit" value="go back">
</form>';
} else {
echo "FAILED TO UPDATE DATA<br>";
}
} catch (mysqli_sql_exception $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</body>
</html>
<html>
<body>
<?php
echo '<body style="background-color:#383A59; color:white">';
$PATIENTID=$_POST["id"];
$PATIENTNAME=$_POST["name"];
$PATIENTADDRESS=$_POST["address"];
$PATIENTCONTACT=$_POST["contact_number"];
$PATIENTGENDER=$_POST["gender"];
try {
$username = "root";
$password = "guru";
$database = "hospital";
$table = "emergency_patient";
$mysqli = new mysqli("localhost", $username, $password, $database);
$query = "update emergency_patient set id = '$PATIENTID', name = '$PATIENTNAME', address = '$PATIENTADDRESS', contact_number = '$PATIENTCONTACT', gender = '$PATIENTGENDER' where id = '$PATIENTID'";
$result = $mysqli->query($query);
if ($result == 1){
echo "successfully edited<br>";
echo "$PATIENTID<br>";
echo "$PATIENTNAME<br>";
echo "$PATIENTADDRESS<br>";
echo "$PATIENTCONTACT<br>";
echo "$PATIENTGENDER<br>";
echo '<form method="post" action="emergency_patient.php">
<input type="submit" value="go back">
</form>';
} else {
echo "FAILED TO UPDATE DATA<br>";
}
} catch (mysqli_sql_exception $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>Hospital</h1>
<form method="post">
<input type="submit" name="addPatient"
class="button" value="add emergency patient" />
<input type="submit" name="showPatient"
class="button" value="show emergency patient" />
<input type="submit" name="editPatient"
class="button" value="edit emergency patient" />
<input type="submit" name="deletePatient"
class="button" value="delete emergency 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();
}
else if(array_key_exists('editPatient', $_POST)) {
editPatient();
}
else if(array_key_exists('deletePatient', $_POST)) {
deletePatient();
}
function addPatient() {
echo '<form method="post" action="added_e_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 editPatient() {
echo '<form method="post" action="edited_e_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 deletePatient() {
echo '<form method="post" action="deleted_e_patient.php">
ID: <input type="text" name="id"><br>
<input type="submit" value="commit">
</form>';
}
function showPatient() {
try {
$username = "root";
$password = "guru";
$database = "hospital";
$table = "emergency_patient";
$mysqli = new mysqli("localhost", $username, $password, $database);
echo "<h2>EMERGENCY PATIENT</h2><ol>";
$query = "SELECT * FROM emergency_patient";
$result = $mysqli->query($query);
echo '<table border="1" cellspacing="2" cellpadding="2">
<tr>
<td> <font face="Monospace">ID</font> </td>
<td> <font face="Monospace">Name</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>
@GurunadhPachappagari
Copy link
Author

also added the edit option

@GurunadhPachappagari
Copy link
Author

added_e_patient is the prompt page when we added a new e patient
edited_e_patient is vise versa
emergency_patient is the main emergency_patient page

@GurunadhPachappagari
Copy link
Author

deleted from file named gistfile1 something which was created by mistake
also added delete functionality

@GurunadhPachappagari
Copy link
Author

fully working final version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment