Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con=mysqli_connect("localhost","table","password","database");
- if (mysqli_connect_errno())
- {
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- }
- $result = mysqli_query($con,"SELECT * FROM recetas_galletas");
- echo "<table border='1'>
- <tr>
- <th>Title</th>
- <th>Description</th>
- </tr>";
- while($row = mysqli_fetch_array($result))
- {
- echo "<tr>";
- echo "<td>" . $row['title'] . "</td>";
- echo "<td>" . $row['description'] . "</td>";
- echo "<td>" . DELETE BUTTON "</td>";
- echo "</tr>";
- }
- echo "</table>";
- mysqli_close($con);
- ?>
- <?php
- $con = mysqli_connect("localhost","table","password","database");
- // Check connection
- if (mysqli_connect_errno())
- {
- die("Failed to connect to MySQL: " . mysqli_connect_error());
- }
- if (!$result = mysqli_query($con,"SELECT * FROM recetas_galletas"))
- {
- die("Error: " . mysqli_error($con));
- }
- ?>
- <table border='1'>
- <tr>
- <th>Title</th>
- <th>Description</th>
- </tr>
- <?php
- while($row = mysqli_fetch_array($result))
- {
- ?>
- <tr>
- <td><?php echo $row['title']; ?></td>
- <td><?php echo $row['description']; ?></td>
- <td><a href="delete.php?id=<?php echo $row['id']; ?>">Delete</a></td>
- </tr>
- <?php
- }
- mysqli_close($con);
- ?>
- </table>
- <?php
- // Your database info
- $db_host = '';
- $db_user = '';
- $db_pass = '';
- $db_name = '';
- if (!isset($_GET['id']))
- {
- echo 'No ID was given...';
- exit;
- }
- $con = new mysqli($db_host, $db_user, $db_pass, $db_name);
- if ($con->connect_error)
- {
- die('Connect Error (' . $con->connect_errno . ') ' . $con->connect_error);
- }
- $sql = "DELETE FROM recetas_galletas WHERE id = ?";
- if (!$result = $con->prepare($sql))
- {
- die('Query failed: (' . $con->errno . ') ' . $con->error);
- }
- if (!$result->bind_param('i', $_GET['id']))
- {
- die('Binding parameters failed: (' . $result->errno . ') ' . $result->error);
- }
- if (!$result->execute())
- {
- die('Execute failed: (' . $result->errno . ') ' . $result->error);
- }
- if ($result->affected_rows > 0)
- {
- echo "The ID was deleted with success.";
- }
- else
- {
- echo "Couldn't delete the ID.";
- }
- $result->close();
- $con->close();
- echo "<td><a href='http://www.site.com/delete.php?id=" . $row['id'] . "'></td>";
- if (is_int($_GET["id"]) {
- $query = "DELETE FROM recetas_galletas WHERE id = " . $_GET["id"];
- $result = mysqli_query($con, $query);
- // Check the result and post confirm message
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement