Href attribute not working

<!DOCTYPE html>
<html>
   <head>
      <link rel="shortcut icon" type="image/png" href="imgs/favicon.png">

      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>URBAN AMENITIES</title>
      <link rel="stylesheet" href="cssmain/bootstrap.min.css">
      <link rel="stylesheet" href="cssmain/style.css">
      <link rel="stylesheet" href="cssmain/fontawesome.min.css">
      <link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto" rel="stylesheet">
   </head>
<?php
    include_once "scripts/checklogin.php";
    
  $servername ="localhost";
  $username ="root";
  $password ="sarasaeed";
  $dbname="services";

   

    if (!check("admin")) {
        header('Location: logout.php');
        exit();
    }

    try {
  $conn = new PDO("mysql:host=$servername;dbname=services","root","sarasaeed");
  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  $sql="SELECT b.*, p.name AS provider_name FROM bookings AS b, providers AS p WHERE b.profession = p.profession and p.city=b.city ORDER BY b.dates DESC";
  $statement = $conn->prepare($sql);  
  $statement->execute();  
  $bookings = $statement->fetchAll();
 

} 
catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
  }


  $conn = null;
 include_once "msg/admin.php";
   
?>
 <div id="header" class="header">
         <nav class="navbar navbar-expand-lg navbar-light text-capitalize">
            <div class="container">
               <a class="navbar-brand" href="#"><img src="imgs/logo.png" alt="#" /></a>
               <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#show-menu" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
               <span class="navbar-toggler-icon"></span>
               </button>
               <div class="collapse navbar-collapse" id="show-menu">
                  <ul class="navbar-nav ml-auto">
                     <li class="nav-item">
                         <a class="nav-link" href="index.html">Home</a>
                     </li>
                    
                     <li class="nav-item">
                        <a class="nav-link" href="update.php">Update admin profile</a>
                     </li>
                     <li class="nav-item">
                        <a class="nav-link active" href="manage.php">Manage bookings</a>
                     </li>
                     <li class="nav-item">
                        <a class="nav-link active" href="index.php">Manage providers</a>
                     </li>
                     <li class="nav-item">
                        <a class="nav-link active" href="logout.php">Log Out</a>
                     </li>
                     
                     
                    
                  </ul>
               </div>
            </div>
         </nav>
      </div>
<div class="container" style="margin-top: 30px; margin-bottom: 60px;">
    <h2 class="text-center"> Bookings </h2>
    <div class="table-responsive">
        <table class="table">
            <tr>
                <th>Name</th>
                <th>Contact</th>
                <th>Address</th>
                <th>Date</th>
                <th>Payment Method</th>
                <th>Queries</th>
                <th>Provider Name</th>
                <th>Action</th>
            </tr>

            <?php foreach($bookings as $booking):?>
            <tr>
            <td><?php echo $booking['fname']; 
            echo $booking['lname']; ?></td>

            

            <td><?php echo $booking['contact']; ?></td>

            <td>
              <?php echo $booking['adder']; ?>
            </td>

            <td>
              <?php echo $booking['dates']; ?> 
            </td>
                
            <td>
              <?php echo $booking['payment']; ?>
            </td>

            <td>
              <?php echo $booking['queries'] ;?> 
            </td>
            
            <td>
            <?php echo $booking['provider_name']; ?> 
            </td>

            <td>
            <a class="btn btn-danger" 
                  href="deletebooking.php?id=<?php $booking->id; ?>">Remove</a>
            </td>
            </tr>
            <?php endforeach; ?>
        </table>
    </div>
</div>

This was code for admin.php file . In this the button of name remove is directed to another webpage but it is not working.

<td>
            <a class="btn btn-danger" 
                  href="deletebooking.php?id=<?php $booking->id; ?>">Remove</a>
            </td>

This line

I don’t really know anything about PHP so I probably shouldn’t try and answer this, but don’t you need to echo the value?

Yes that worked but now the deletebooking.php webpage is not getting its ID

In case ,

<?php

include_once "scripts/checklogin.php";
include_once "scripts/helpers.php";


if (!check("admin")) {
    header('Location: logout.php');
    exit();
}
if (isset($_GET['id'])) {
    
    $id=$_GET['id'];
    try {
                $conn = new PDO('mysql:host=localhost;dbname=services; charset=utf8','root','sarasaeed');
                $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                $sql = "DELETE * FROM bookings WHERE id='$id'";
                $isRemoved= $conn->prepare($sql);  
                $isRemoved->execute();  
                if ($isRemoved) {
                    header('Location: admin.php?msg=success');
                    exit();
                } else {
                    header('Location: admin.php?msg=failed');
                    exit();
                }

                
            }
            catch(PDOException $e) {
                echo "Connection failed: " . $e->getMessage();
            }
                $conn = null;
}            
        
?>

OH !!
sql query was wrong

Corrected one :

delete from bookings where id=$id;```
1 Like

So it’s working how? If so, good job fixing it.

Happy coding!