Skip to content

Instantly share code, notes, and snippets.

@samroar
Created November 19, 2014 17:12
Show Gist options
  • Save samroar/0b4a87ea15f18449f808 to your computer and use it in GitHub Desktop.
Save samroar/0b4a87ea15f18449f808 to your computer and use it in GitHub Desktop.
<?php
include('connection.php');
include('restrict-login.php');
if(isset($_POST['action'])) {
if($_POST['action'] == 'add') {
$parameters = array($_POST['firstName'], $_POST['lastName'], $_POST['sex'], $_POST['dob'], $_POST['email'], $_POST['password'], $_POST['type'], $_POST['phoneNo']);
if($_POST['what'] == 'admin') {
$query = $dbh->prepare('INSERT INTO users (firstName, lastName, sex, dob, email, type, password, phoneNo) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
} elseif($_POST['what'] == 'patient') {
$query = $dbh->prepare('INSERT INTO users (firstName, lastName, sex, dob, email, type, password, phoneNo, experience) VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
$parameters[] = $_POST['experience'];
} elseif($_POST['what'] == 'admin') {
$query = $dbh->prepare('INSERT INTO users (firstName, lastName, sex, dob, email, type, password, phoneNo, history, bloodGroup) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)');
$parameters[] = $_POST['history'];
$parameters[] = $_POST['bloodGroup'];
}
$query->execute($parameters);
}
if($_POST['action'] == 'edit') {
$parameters = array($_POST['firstName'], $_POST['lastName'], $_POST['sex'], $_POST['dob'], $_POST['email'], $_POST['password'], $_POST['phoneNo']);
if($_POST['what'] == 'admin') {
$query = $dbh->prepare('UPDATE users SET firstName = ?, lastName = ?, sex = ?, dob = ?, email = ?, password = ?, phoneNo = ? WHERE id = ?');
} elseif($_POST['what'] == 'doctor') {
$query = $dbh->prepare('UPDATE users SET firstName = ?, lastName = ?, sex = ?, dob = ?, email = ?, password = ?, phoneNo = ?, experience = ? WHERE id = ?');
$parameters[] = $_POST['experience'];
} elseif($_POST['what'] == 'patient') {
$query = $dbh->prepare('UPDATE users SET firstName = ?, lastName = ?, sex = ?, dob = ?, email = ?, password = ?, phoneNo = ?, history = ?, bloodGroup = ? WHERE id = ?');
$parameters[] = $_POST['history'];
$parameters[] = $_POST['bloodGroup'];
}
$parameters[] = $_POST['id'];
$query->execute($parameters);
}
if($_POST['action'] == 'delete') {
if($_POST['what'] == "admin") {
$query = $dbh->prepare('DELETE FROM users WHERE id = ?');
} elseif($_POST['what'] == 'doctor') {
$query = $dbh->prepare('DELETE FROM users WHERE id = ?');
} elseif($_POST['what'] == 'patient') {
$query = $dbh->prepare('DELETE FROM users WHERE id = ?');
}
$query->execute();
}
}
if($_SESSION['type'] == 0) {
$rows = $dbh->query('SELECT firstName, lastName, type FROM users');
$type = array('Admin', 'Doctor', 'Patient');
?><!DOCTYPE html>
<html>
<head>
<title>users</title>
</head>
<body>
<table>
<tr>
<th>Type</th>
<th>Name</th>
<th>Edit</th>
</tr>
<?php foreach($rows as $row) { ?>
<tr>
<td><?php echo $type[$row['type']]; ?></td>
<td><?php echo $row['firstName'].' '.$row['lastName'] ?></td>
<td><a href="?id=<?php echo $row['id']; ?>">Edit</a></td>
</tr>
<?php } ?>
</table>
<?php } ?>
<form action="" method="POST">
<label><br>First Name</br><input type = "text" name = "firstName"></label>
<label><br>Last Name</br><input type = "text" name = "lastName"></label>
<label><br>Sex</br><input type = "text" name = "sex"></label>
<label><br>DOB</br><input type = "date" name = "dob"></label>
<label><br>Email</br><input type = "text" name = "email"></label>
<label><br>Type</br><input type = "text" name = "type"></label>
<label><br>Password</br><input type = "text" name = "password"></label>
<label><br>Experience</br><input type = "number" name = "experience"></label>
<label><br>History</br><input type = "text" name = "history"></label>
<label><br>Blood Group</br><input type = "text" name = "bloodGroup"></label>
<input type = "hidden" name = "action" value = ""></input>
<input type = " hidden" name = "what" value = " "></input>
</form>
</body>
</html>
<?php
if(isset($_SESSION['id'])) {
if($_SESSION['type'] == 1 || $_SESSION['type'] == 2) {
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment