Hello mga master, ask ko lang po bakit di nag e-echo yung status at di nagpapakita yung approve button(add) at cancel (delete), ano po kaya ang mali or kulang? Thank you po sa sasagot
DB table:
admin webpage:
php code:
html code:
Dito naman po sa part ng user webpage, hindi o nag e-echo lahat ng user information, status at button rin po sa action which is cancel
user webpage:
php code:
Html code:
pasensya po sa pa spoonfeed noob pa po kasi hehe
DB table:
admin webpage:
php code:
PHP:
<?php
include("config.php");
session_start();
if(!isset($_SESSION['user'])){
header("location: Login.php");
}
$user_check=$_SESSION['user'];
$sql="SELECT * FROM users WHERE username='$user_check'";
$stmt=$conn->query($sql);
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$login_user=$row['name'];
$login_access=$row['acc_type'];
//code to update order
if (isset($_POST['delUser'])){
$sql=" UPDATE appointments SET status='Approved' WHERE appointment_id=:appointmentid";
$stmt=$conn->prepare($sql);
$stmt->execute([':appointmentid'=>$_POST ['appointment_id']]);
$services=$_POST['services'];
$sql="SELECT * FROM services WHERE services='$services'";
$stmt=$conn->query($sql);
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$stmt=$conn->query($sql);
}
?>
html code:
Code:
<div class="mt-sm-5"></div>
<main role="main" class="container pt-3">
<div class="card">
<div class="card-header"><font color="black">
<h2>List of Appointments</h2>
</div>
<div class="card body"><font color="black">
<table class="table table-light">
<?php
$sql = "SELECT * FROM appointments";
$stmt=$conn->query('SELECT * FROM appointments');
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row==null){ ?>
<td class="text-center">NO APPOINTMENTS</td>
<?php }
else{
?>
<head>
<tr>
<th>Name</th>
<th>Contact</th>
<th>Services</th>
<th>Doctors</th>
<th>Status</th>
<th>Action</th>
</tr>
</head>
<tbody>
<?php
$sql = "SELECT * FROM appointments";
$stmt=$conn->query('SELECT * FROM appointments');
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['contact']; ?></td>
<td><?php echo $row['services']; ?></td>
<td><?php echo $row['doctor']; ?></td>
<td><?php echo $row['status']; ?></td>
<td>
<?php if($row['status']=="Pending"){?>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#delModal" onclick="approveappointment_id(<?php echo $row['appointment_id'] ?> , '<?php echo $row['services'] ?>', )">Approve</button>
<?php }?>
</td>
</tr>
<?php } }
$conn = null;
?>
</tbody>
</table>
<!------------------- Modal to Approve Order -------------------->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Approve Order</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="" method="POST">
<div class="modal-body">
<p>Approve order?</p>
</div>
<div class="modal-footer">
<input type="hidden" name="appointment_id" id="appointment_id">
<input type="hidden" name="services" id="services">
<input type="hidden" name="doctors" id="doctors">
<button type="submit" class="btn btn-primary" name="delUser">Yes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<?php }?>
<?php if($login_access=="user"){?>
<?php
header("location:restriction404.php");
?>
<?php }?>
</body>
</html>
<script src="bootstrap/jquery/jquery-3.6.0.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<script>
function approveappointment_id(appointment_id, services, doctors){
document.getElementById('appointment_id').value=appointment_id;
document.getElementById('services').value=services;
document.getElementById('doctors').value=doctors;
}
</script>
Dito naman po sa part ng user webpage, hindi o nag e-echo lahat ng user information, status at button rin po sa action which is cancel
user webpage:
php code:
PHP:
<?php
include("config.php");
session_start();
$user_check=$_SESSION['user'];
$sql="SELECT * FROM users WHERE username='$user_check'";
$stmt=$conn->query($sql);
$row=$stmt->fetch(PDO::FETCH_ASSOC);
$login_user=$row['username'];
$login_access=$row['acc_type'];
$id=$row['user_id'];
//code to update order
if (isset($_POST['delUser'])){
$sql=" UPDATE appointments SET status='Canceled' WHERE appointment_id=:appoid";
$stmt=$conn->prepare($sql);
$stmt->execute([':appoid'=>$_POST['appointment_id']]);
}
?>
Html code:
HTML:
<div class="mt-sm-5"></div>
<main role="main" class="container pt-3">
<div class="card">
<div class="card-header">
<h2><font color="black">My Appointments</h2>
</div>
<div class="card body">
<table class="table table-light"><font color="black">
<?php
$sql = "SELECT * FROM appointments WHERE name = '$login_user'";
$stmt = $conn->query("SELECT * FROM appointments WHERE name = '$login_user' ");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row==null){ ?>
<td class="text-center">NO APPOINTMENTS</td>
<?php }
else{
?>
<head>
<tr>
<th>Name</th>
<th>Contact</th>
<th>Services</th>
<th>Doctors</th>
<th>Status</th>
<th>Action</th>
</tr>
</head>
<tbody>
<?php
$sql = "SELECT * FROM appointments WHERE user_id = '$id'";
$stmt = $conn->query($sql);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['contact']; ?></td>
<td><?php echo $row['services']; ?></td>
<td><?php echo $row['doctor']; ?></td>
<td><?php echo $row['status']; ?></td>
<td>
<?php if($row['status']=="Pending"){?>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delModal" onclick="approveappointment_id(<?php echo $row['appointment_id'] ?>)">Cancel</button>
<?php }?>
</td>
</tr>
<?php } }
$conn = null;
?>
</tbody>
</table>
<!------------------- Modal to Approve Order -------------------->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Cancel Order</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="" method="POST">
<div class="modal-body">
<p>Cancel order?</p>
</div>
<div class="modal-footer">
<input type="hidden" name="appointment_id" id="order_id">
<button type="submit" class="btn btn-primary" name="delUser">Yes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
</div>
</form>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
<script src="bootstrap/jquery/jquery-3.6.0.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<script>
function approveappointment_id(appointment_id){
document.getElementById('appointment_id').value=appointment_id;
}
</script>
pasensya po sa pa spoonfeed noob pa po kasi hehe
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
Last edited: