Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(isset($_SESSION["username"]))
- {
- // Welcome Alert
- $welcomeuser = '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>Login Success, Welcome - '.$_SESSION["username"].'</h3><div>';
- }
- else
- {
- header("location:loginnew.php");
- }
- // function to insert data in the database
- function insertappointment($db) {
- if(!isset($_POST['submit'])) {
- return;
- }
- $errMsg = '';
- // get the data from the front end
- $fullname = $_POST['fullname'];
- $day = $_POST['day'];
- $time = $_POST['time'];
- // check the values
- if( !$fullname || !$day || !$time) {
- echo 'One or more fields are empty.';
- return;
- }
- else {
- // escape special characters in a string for use in the SQL statement
- }
- // create a query
- $userid = $_SESSION['userid'];
- $sqlQuery = "INSERT INTO `appointments` (`userid`, `FullName`, `Day`, `Time`) VALUES (?,?,?,?)";
- //prepare the query
- $query = $db->prepare($sqlQuery);
- //execute the query
- $query->execute(array($userid,$fullname,$day,$time));
- // check if the student was successfully inserted in the database
- if ($query) {
- echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>The appointment was inserted in the database</h3></div>';
- }
- else {
- // print the error generated
- echo '<div id="alert1" class="alert alert-danger alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>The appointment was not inserted in the database</h3></div>';
- }
- }
- function deleteappointment($db) {
- if(!isset($_POST['delete'])) {
- return;
- }
- $errMsg = '';
- // create a query
- $userid = $_SESSION['userid'];
- $sqlQuery = "DELETE FROM `appointments` WHERE `userid`";
- //prepare the query
- $query = $db->prepare($sqlQuery);
- //execute the query
- $query->execute(array($userid));
- // check if the student was successfully inserted in the database
- if ($query) {
- echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>The appointment was deleted from the database</h3></div>';
- }
- else {
- // print the error generated
- echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>The appointment was not deleted from the database</h3></div>';
- }
- }
- function updateappointment($db) {
- if(!isset($_POST['update'])) {
- return;
- }
- $errMsg = '';
- // get the data from the front end
- $fullname = $_POST['fullname'];
- $day = $_POST['day'];
- $time = $_POST['time'];
- // create a query
- $userid = $_SESSION['userid'];
- $sqlQuery = "UPDATE `appointments` SET `FullName`=`fullname` ,`Day`=`day`, `Time`=`time` WHERE `userid`";
- //prepare the query
- $query = $db->prepare($sqlQuery);
- //execute the query
- $query->execute(array($fullname,$day,$time));
- // check if the student was successfully inserted in the database
- if ($query) {
- echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>The appointment was updated in the database</h3></div>';
- }
- else {
- // print the error generated
- echo '<div id="alert1" class="alert alert-success alert-dismissible" role="alert">
- <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><h3>The appointment was not updated in the database</h3></div>';
- }
- }
- /* Main body */
- //connect to the DB
- $dsn = 'mysql:host=localhost;dbname=oversurgery';
- $user = 'toxic';
- $password = 'sysop2018';
- try {
- $db = new PDO($dsn, $user, $password);
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- // echo 'Connection failed: ' . $e->getMessage();
- die('Sorry, database problem');
- }
- insertappointment($db);
- deleteappointment($db);
- updateappointment($db);
- ?>
- <?php
- //connect to the DB
- $dsn = 'mysql:host=localhost;dbname=oversurgery';
- $user = 'toxic';
- $password = 'sysop2018';
- try {
- $db = new PDO($dsn, $user, $password);
- } catch (PDOException $e) {
- die('Sorry, database problem');
- }
- // create a query
- $userid = $_SESSION['userid'];
- $sql= "SELECT * FROM appointments WHERE userid=:userid";
- $stmt = $db->prepare($sql);
- $stmt->execute([':userid' => $userid]);
- $row =$stmt->fetchObject();
- $row->Day;
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Appointments</title>
- <link rel="stylesheet" type="text/css" href="stylesheets/bootstrap.css">
- <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
- </head>
- <body>
- <!-- Navbar starts-->
- <nav class="navbar navbar-inverse">
- <div class="container">
- <!-- Brand and toggle get grouped for better mobile display -->
- <div class="navbar-header">
- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="index.html">Over Surgery</a>
- </div>
- <!-- Collect the nav links, forms, and other content for toggling -->
- <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
- <ul class="nav navbar-nav">
- <li><a href="index.html">Home <span class="sr-only">(current)</span></a></li>
- <li><a href="index.html">About Us</a></li>
- <li><a href="contact.html">Contact</a></li>
- </ul>
- <ul class="nav navbar-nav navbar-right">
- <li><a href="register.php"><span><i class="fas fa-user-plus"></i>Register</span></a></li>
- <li><a href="login.php"><span><i class="fas fa-sign-in-alt"></i>Login</span></a></li>
- </ul>
- </div><!-- /.navbar-collapse -->
- </div><!-- /.container-fluid -->
- </nav>
- <!-- Navbar Ends -->
- <!-- content -->
- <div class="container">
- <div class="row">
- <div class="col-md-9">
- <div id="dashboard">
- <h2>Appointments</h2>
- <div class="col-md-7">
- <form class="form-horizontal apppagedashboard" method="POST">
- <!-- Name -->
- <label class="control-label" for="fullname">Full Name:</label>
- <input type="text" id="fullname" name="fullname" placeholder="Full Name" class="input-xlarge">
- <p class="help-block" style="color: black;">Please enter your full name.</p>
- <!-- Day -->
- <label class="control-label" for="day">Day:</label>
- <select name="day">
- <option value="Monday">Monday</option>
- <option value="Tuesday">Tuesday</option>
- <option value="Wednesday">Wednesday</option>
- <option value="Thursday">Thursday</option>
- <option value="Friday">Friday</option>
- </select>
- <p class="help-block" style="color: black;"></p>
- <!-- Time -->
- <label class="control-label" for="time">Time:</label>
- <select name="time">
- <option value="9:00 - 9:50">9:00 - 9:50</option>
- <option value="10:00 - 10:50">10:00 - 10:50</option>
- <option value="11:00 - 11:50">11:00 - 11:50</option>
- <option value="12:00 - 12:50">12:00 - 12:50</option>
- <option value="13:00 - 13:50">13:00 - 13:50</option>
- <option value="14:00 - 14:50">14:00 - 14:50</option>
- <option value="15:00 - 15:50">15:00 - 15:50</option>
- <option value="16:00 - 16:50">16:00 - 16:50</option>
- </select>
- <p class="help-block" style="color: black;"></p>
- <div class="control-group">
- <!-- Submit Button -->
- <div class="controls">
- <input type="submit" class="btn btn-success" name="submit" value="Submit"></input>
- <input type="submit" class="btn btn-primary" name="update" value="Update"></input>
- <input type="submit" class="btn btn-danger" name="delete" value="Delete"></input>
- </div>
- </div>
- </form>
- </div>
- <div class="col-md-5 apppagedashboardleft">
- <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>
- <div class="controls">
- </div>
- </div>
- </div>
- </div>
- <div class="col-md-3 sidemenumargin">
- <div class="sidemenu">
- <p>Main Menu</p>
- <a href="dashboard.html">Profile<i class="fas fa-user sidemenuicon"></i></a>
- <a href="appointments.html" class="active">Appointments<i class="fas fa-book sidemenuicon"></i></a>
- <a href="prescriptions.html">Prescriptions<i class="fas fa-sticky-note sidemenuicon"></i></a>
- <a href="results.html">Results<i class="fas fa-file sidemenuicon"></i></a>
- <a href="livechat.html">Live chat<i class="fas fa-comment-alt sidemenuicon"></i></a>
- <a href="drnsavailability.html">Doctors & Nurses Availability<i class="fas fa-user-md sidemenuicon"></i></a>
- <a href="logout.php">Log out<i class="fas fa-sign-out-alt sidemenuicon"></i></a>
- </div>
- </div>
- </div>
- </div>
- <!-- Scripts -->
- <script
- src="http://code.jquery.com/jquery-3.3.1.js"
- integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
- crossorigin="anonymous"></script>
- <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
- <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement