Advertisement
Guest User

Untitled

a guest
Apr 9th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(isset($_SESSION["username"]))
  4. {
  5. // Welcome Alert
  6. $welcomeuser = '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
  7. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>Login Success, Welcome - '.$_SESSION["username"].'</h3><div>';
  8. }
  9. else
  10. {
  11. header("location:loginnew.php");
  12. }
  13. // function to insert data in the database
  14. function insertappointment($db) {
  15.  
  16. if(!isset($_POST['submit'])) {
  17. return;
  18. }
  19. $errMsg = '';
  20.  
  21. // get the data from the front end
  22. $fullname = $_POST['fullname'];
  23. $day = $_POST['day'];
  24. $time = $_POST['time'];
  25.  
  26.  
  27. // check the values
  28. if( !$fullname || !$day || !$time) {
  29. echo 'One or more fields are empty.';
  30. return;
  31. }
  32. else {
  33. // escape special characters in a string for use in the SQL statement
  34. }
  35.  
  36. // create a query
  37. $userid = $_SESSION['userid'];
  38. $sqlQuery = "INSERT INTO `appointments` (`userid`, `FullName`, `Day`, `Time`) VALUES (?,?,?,?)";
  39.  
  40.  
  41. //prepare the query
  42. $query = $db->prepare($sqlQuery);
  43. //execute the query
  44. $query->execute(array($userid,$fullname,$day,$time));
  45.  
  46. // check if the student was successfully inserted in the database
  47. if ($query) {
  48. echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
  49. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>The appointment was inserted in the database</h3></div>';
  50. }
  51. else {
  52. // print the error generated
  53. echo '<div id="alert1" class="alert alert-danger alert-dismissible" role="alert">
  54. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>The appointment was not inserted in the database</h3></div>';
  55. }
  56.  
  57. }
  58. function deleteappointment($db) {
  59.  
  60. if(!isset($_POST['delete'])) {
  61. return;
  62. }
  63. $errMsg = '';
  64.  
  65. // create a query
  66. $userid = $_SESSION['userid'];
  67. $sqlQuery = "DELETE FROM `appointments` WHERE `userid`";
  68.  
  69.  
  70. //prepare the query
  71. $query = $db->prepare($sqlQuery);
  72. //execute the query
  73. $query->execute(array($userid));
  74.  
  75. // check if the student was successfully inserted in the database
  76. if ($query) {
  77. echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
  78. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>The appointment was deleted from the database</h3></div>';
  79. }
  80. else {
  81. // print the error generated
  82. echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
  83. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>The appointment was not deleted from the database</h3></div>';
  84. }
  85.  
  86. }
  87. function updateappointment($db) {
  88.  
  89. if(!isset($_POST['update'])) {
  90. return;
  91. }
  92. $errMsg = '';
  93.  
  94. // get the data from the front end
  95. $fullname = $_POST['fullname'];
  96. $day = $_POST['day'];
  97. $time = $_POST['time'];
  98.  
  99. // create a query
  100. $userid = $_SESSION['userid'];
  101. $sqlQuery = "UPDATE `appointments` SET `FullName`=`fullname` ,`Day`=`day`, `Time`=`time` WHERE `userid`";
  102.  
  103. //prepare the query
  104. $query = $db->prepare($sqlQuery);
  105. //execute the query
  106. $query->execute(array($fullname,$day,$time));
  107.  
  108. // check if the student was successfully inserted in the database
  109. if ($query) {
  110. echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
  111. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>The appointment was updated in the database</h3></div>';
  112. }
  113. else {
  114. // print the error generated
  115. echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
  116. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><h3>The appointment was not updated in the database</h3></div>';
  117. }
  118.  
  119. }
  120.  
  121.  
  122. /* Main body */
  123. //connect to the DB
  124. $dsn = 'mysql:host=localhost;dbname=oversurgery';
  125. $user = 'toxic';
  126. $password = 'sysop2018';
  127.  
  128. try {
  129. $db = new PDO($dsn, $user, $password);
  130. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  131. } catch (PDOException $e) {
  132. // echo 'Connection failed: ' . $e->getMessage();
  133. die('Sorry, database problem');
  134. }
  135.  
  136. insertappointment($db);
  137. deleteappointment($db);
  138. updateappointment($db);
  139. ?>
  140.  
  141. <?php
  142.  
  143. //connect to the DB
  144. $dsn = 'mysql:host=localhost;dbname=oversurgery';
  145. $user = 'toxic';
  146. $password = 'sysop2018';
  147.  
  148. try {
  149. $db = new PDO($dsn, $user, $password);
  150. } catch (PDOException $e) {
  151. die('Sorry, database problem');
  152. }
  153.  
  154. // create a query
  155. $userid = $_SESSION['userid'];
  156. $sql= "SELECT * FROM appointments WHERE userid=:userid";
  157. $stmt = $db->prepare($sql);
  158. $stmt->execute([':userid' => $userid]);
  159. $row =$stmt->fetchObject();
  160. $row->Day;
  161.  
  162. ?>
  163.  
  164.  
  165. <!DOCTYPE html>
  166. <html>
  167. <head>
  168. <title>Appointments</title>
  169. <link rel="stylesheet" type="text/css" href="stylesheets/bootstrap.css">
  170. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  171. </head>
  172. <body>
  173. <!-- Navbar starts-->
  174. <nav class="navbar navbar-inverse">
  175. <div class="container">
  176. <!-- Brand and toggle get grouped for better mobile display -->
  177. <div class="navbar-header">
  178. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  179. <span class="sr-only">Toggle navigation</span>
  180. <span class="icon-bar"></span>
  181. <span class="icon-bar"></span>
  182. <span class="icon-bar"></span>
  183. </button>
  184. <a class="navbar-brand" href="index.html">Over Surgery</a>
  185. </div>
  186.  
  187. <!-- Collect the nav links, forms, and other content for toggling -->
  188. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  189. <ul class="nav navbar-nav">
  190. <li><a href="index.html">Home <span class="sr-only">(current)</span></a></li>
  191. <li><a href="index.html">About Us</a></li>
  192. <li><a href="contact.html">Contact</a></li>
  193. </ul>
  194. <ul class="nav navbar-nav navbar-right">
  195. <li><a href="register.php"><span><i class="fas fa-user-plus"></i>Register</span></a></li>
  196. <li><a href="login.php"><span><i class="fas fa-sign-in-alt"></i>Login</span></a></li>
  197. </ul>
  198. </div><!-- /.navbar-collapse -->
  199. </div><!-- /.container-fluid -->
  200. </nav>
  201. <!-- Navbar Ends -->
  202.  
  203.  
  204. <!-- content -->
  205. <div class="container">
  206. <div class="row">
  207. <div class="col-md-9">
  208.  
  209. <div id="dashboard">
  210. <h2>Appointments</h2>
  211.  
  212.  
  213. <div class="col-md-7">
  214. <form class="form-horizontal apppagedashboard" method="POST">
  215.  
  216. <!-- Name -->
  217. <label class="control-label" for="fullname">Full Name:</label>
  218. <input type="text" id="fullname" name="fullname" placeholder="Full Name" class="input-xlarge">
  219. <p class="help-block" style="color: black;">Please enter your full name.</p>
  220.  
  221.  
  222.  
  223. <!-- Day -->
  224. <label class="control-label" for="day">Day:</label>
  225. <select name="day">
  226. <option value="Monday">Monday</option>
  227. <option value="Tuesday">Tuesday</option>
  228. <option value="Wednesday">Wednesday</option>
  229. <option value="Thursday">Thursday</option>
  230. <option value="Friday">Friday</option>
  231. </select>
  232. <p class="help-block" style="color: black;"></p>
  233.  
  234.  
  235.  
  236.  
  237. <!-- Time -->
  238. <label class="control-label" for="time">Time:</label>
  239. <select name="time">
  240. <option value="9:00 - 9:50">9:00 - 9:50</option>
  241. <option value="10:00 - 10:50">10:00 - 10:50</option>
  242. <option value="11:00 - 11:50">11:00 - 11:50</option>
  243. <option value="12:00 - 12:50">12:00 - 12:50</option>
  244. <option value="13:00 - 13:50">13:00 - 13:50</option>
  245. <option value="14:00 - 14:50">14:00 - 14:50</option>
  246. <option value="15:00 - 15:50">15:00 - 15:50</option>
  247. <option value="16:00 - 16:50">16:00 - 16:50</option>
  248. </select>
  249. <p class="help-block" style="color: black;"></p>
  250.  
  251.  
  252.  
  253. <div class="control-group">
  254. <!-- Submit Button -->
  255. <div class="controls">
  256. <input type="submit" class="btn btn-success" name="submit" value="Submit"></input>
  257. <input type="submit" class="btn btn-primary" name="update" value="Update"></input>
  258. <input type="submit" class="btn btn-danger" name="delete" value="Delete"></input>
  259.  
  260. </div>
  261. </div>
  262.  
  263. </form>
  264. </div>
  265.  
  266. <div class="col-md-5 apppagedashboardleft">
  267. <div id="bookalert" class="alert alert-success" role="alert">You habe booked your appointment on: <?php echo $row->Day;?> between <?php echo $row->Time;?></div>
  268. <div class="controls">
  269.  
  270.  
  271.  
  272. </div>
  273. </div>
  274.  
  275.  
  276.  
  277.  
  278.  
  279. </div>
  280. </div>
  281.  
  282.  
  283. <div class="col-md-3 sidemenumargin">
  284.  
  285. <div class="sidemenu">
  286. <p>Main Menu</p>
  287. <a href="dashboard.html">Profile<i class="fas fa-user sidemenuicon"></i></a>
  288. <a href="appointments.html" class="active">Appointments<i class="fas fa-book sidemenuicon"></i></a>
  289. <a href="prescriptions.html">Prescriptions<i class="fas fa-sticky-note sidemenuicon"></i></a>
  290. <a href="results.html">Results<i class="fas fa-file sidemenuicon"></i></a>
  291. <a href="livechat.html">Live chat<i class="fas fa-comment-alt sidemenuicon"></i></a>
  292. <a href="drnsavailability.html">Doctors & Nurses Availability<i class="fas fa-user-md sidemenuicon"></i></a>
  293. <a href="logout.php">Log out<i class="fas fa-sign-out-alt sidemenuicon"></i></a>
  294. </div>
  295.  
  296. </div>
  297. </div>
  298. </div>
  299.  
  300.  
  301.  
  302. <!-- Scripts -->
  303. <script
  304. src="http://code.jquery.com/jquery-3.3.1.js"
  305. integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
  306. crossorigin="anonymous"></script>
  307. <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  308. <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
  309.  
  310. </body>
  311. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement