Created
November 19, 2014 18:03
-
-
Save samroar/a5fc721409406baa0ff8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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> | |
</body> | |
</html> | |
<?php } ?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>users</title> | |
</head> | |
<body> | |
<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 type = " hidden" name = "what" value = ""> | |
</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