Php 通过生成的带有记录的表从mysql中删除行
我用了2页。在一个页面上,它生成一个带有记录和删除按钮的表。按delete键后,进入第二页,该页应删除记录。但事实并非如此。下面是我正在使用的代码 附:代码改编自我不久前通过谷歌找到的一个教程 删除_overzicht.phpPhp 通过生成的带有记录的表从mysql中删除行,php,mysql,sql-delete,Php,Mysql,Sql Delete,我用了2页。在一个页面上,它生成一个带有记录和删除按钮的表。按delete键后,进入第二页,该页应删除记录。但事实并非如此。下面是我正在使用的代码 附:代码改编自我不久前通过谷歌找到的一个教程 删除_overzicht.php <?php // Load Joomla! configuration file require_once('../../../configuration.php'); // Create a JConfig object $config = new JConfig
<?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!");
}
?>
感谢所有愿意帮忙的人 以下答案来自用户Andrewsi。这一答案已张贴在评论中
DELETE的语法是
DELETE FROM
-您需要删除*
DELETE的语法是DELETE FROM
-您需要删除*
不要使用GET查询执行删除操作:@andrewski感谢您的回答。这是正确的钱。它工作得很好。你介意把它作为答案贴出来吗。这样我才能选择它作为正确答案。@MarcB谢谢你的警告。我很高兴你能帮助我。如果你能告诉我怎么做的话,我会很高兴的。因为我不知道。再次感谢。@MarcB执行删除操作的安全性如何?