我正在使用2页。在一个页面上,它生成一个包含记录和删除按钮的表。按删除后,它将转到第二页,该页应删除该记录。但它并没有。下面是我正在使用的代码。
PS:该代码改编自我之前通过Google发现的教程。
delete_overzicht.php
<?php
// Load Joomla! configuration file
require_once('../../../configuration.php');
// Create a JConfig object
$config = new JConfig();
// Get the required codes from the configuration file
$server = $config->host;
$username = $config->user;
$password = $config->password;
$database = $config->db;
// Connect to db
$con = mysqli_connect($server,$username,$password,$database);
if (!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,$database);
// Get results
$result = mysqli_query($con,"SELECT * FROM cypg8_overzicht");
echo "<table border='1' id='example' class='tablesorter'><thead><tr><th>Formulier Id</th><th>Domeinnaam</th><th>Bedrijfsnaam</th><th>Datum</th><th>Periode</th><th>Subtotaal</th><th>Dealernaam</th><th>Verwijderen</th></tr></thead><tbody>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['formuliernummer'] . "</td>";
echo "<td>" . $row['domeinnaam'] . "</td>";
echo "<td>" . $row['bedrijfsnaam'] . "</td>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['periode'] . "</td>";
echo "<td> € " . $row['subtotaal'] . "</td>";
echo "<td>" . $row['dealercontactpersoon'] . "</td>";
echo "<td><a href='delete.php?id=" . $row['id'] . "'>Verwijderen </a></td>";
echo "</tr>";
}
echo "</tbody></table>";
mysqli_close($con);
?>
delete.php
<?php
// Load Joomla! configuration file
require_once('../../../configuration.php');
// Create a JConfig object
$config = new JConfig();
// Get the required codes from the configuration file
$server = $config->host;
$username = $config->user;
$password = $config->password;
$database = $config->db;
// Connect to db
$con = mysqli_connect($server,$username,$password,$database);
if (!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,$database);
// Check whether the value for id is transmitted
if (isset($_GET['id'])) {
// Put the value in a separate variable
$id = $_GET['id'];
// Query the database for the details of the chosen id
$result = mysqli_query($con,"DELETE * FROM cypg8_overzicht WHERE id = $id");
} else {
die("No valid id specified!");
}
?>
感谢所有愿意帮助的人!
答案 0 :(得分:1)
以下答案来自用户Andrewsi。这个答案发表在评论中。
DELETE的语法为DELETE FROM
- 您需要删除*