Jump to content

rruseva

New Members
  • Posts

    3
  • Joined

  • Last visited

rruseva's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I missed that..the name of the table is not table..
  2. This is how I fixed it with the help of this comment. I just want to make the delete_booking.php part to work: <?php include 'db_connection.php'; $sqlQuery = 'SELECT * FROM room_reservation'; $result = mysqli_query($link, $sqlQuery) or die(mysqli_error($link)); if ($result) { $tableStyle = "style='border:1px solid white; border-collapse:collapse; text-align:center; background-color:#8f50fb'"; $buttonStyle = "style='background-color: #8f50fb; color=white; padding: 14px 25px; text-align:center; border-radius:10px'"; echo "<form action='delete_booking.php' method='POST'><table class='table table-striped table-borderrer'><tr><th>Name</th><th>Room</th><th>CheckIn</th><th>CheckOut</th><th>Actions</th></tr>"; while ($row = mysqli_fetch_array($result)) { //to loop through the result row by row echo "<tr>"; echo "<td>".$row['Name']."</td>"; echo "<td>".$row['Room']."</td>"; echo "<td>".$row['CheckIn']."</td>"; echo "<td>".$row['CheckOut']."</td>"; echo "<td><div class='btn-group'>"; echo "<button type='submit' name='Name'>Delete</button>"; echo"</div></td>"; echo "</tr>"; } echo "</table></form>"; } echo '<p><a href="add_reservation.php">Add a new student</a></p>'; echo "<a href='homepage.html' $buttonStyle>Go back to homepage</a>" ?> <?php // Connect to the database include 'db_connection.php'; // Check if the form has been submitted if (isset($_POST['Name'])) { // Get the ID of the record to be deleted $name = $_POST['Name']; // Delete the record from the database $query = "DELETE FROM table WHERE Name = '$name'"; $result = mysqli_query($link, $query) or die(mysqli_error($link)); if (!$result) { die("Failed to delete record: " . mysqli_error($link)); } else { echo 'Deletion successful.'; } // Redirect to the home page header("Location: show_bookings.php"); exit; } ?> But the name is not retrieved: Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'table WHERE Name = ''' at line 1
  3. I'm new to php and currently I'm preparing a small crud project. I have a html homepage, add_reservation.php which is working, show_bookings.php and delete_booking.php. I can not delete a booking. Here is my show_bookings.php code: <?php include 'db_connection.php'; $sqlQuery = 'SELECT * FROM room_reservation'; $result = mysqli_query($link, $sqlQuery) or die(mysqli_error($link)); if ($result) { $tableStyle = "style='border:1px solid white; border-collapse:collapse; text-align:center; background-color:#8f50fb'"; $buttonStyle = "style='background-color: #8f50fb; color=white; padding: 14px 25px; text-align:center; border-radius:10px'"; echo "<table class='table table-striped table-borderrer'><tr><th>Name</th><th>Room</th><th>CheckIn</th><th>CheckOut</th><th>Actions</th></tr>"; while ($row = mysqli_fetch_array($result)) { //to loop through the result row by row echo "<tr>"; echo "<td>".$row['Name']."</td>"; echo "<td>".$row['Room']."</td>"; echo "<td>".$row['CheckIn']."</td>"; echo "<td>".$row['CheckOut']."</td>"; echo "<td><div class='btn-group'>"; echo "<a class='btn btn-danger' href='./delete_booking.php?Name=" .$row['Name'] ."'>Delete</a>"; echo"</div></td>"; echo "</tr>"; } echo "</table>"; } echo '<p><a href="add_reservation.php">Add a new student</a></p>'; echo "<a href='homepage.html' $buttonStyle>Go back to homepage</a>" ?> And here is my delete_booking.php code: <?php // Connect to the database include 'db_connection.php'; // Check if the form has been submitted if (isset($_GET['Name'])) { // Get the ID of the record to be deleted $name = $_GET['Name']; // Delete the record from the database $query = "DELETE FROM table WHERE Name = $name"; // mysqli_query($db, $query); // Redirect to the home page // header("Location: show_bookings.php"); // exit; } ?> I hope that someone could tell me where I'm wrong.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.