0

我正在使用 2 页。在一个页面上,它会生成一个包含记录和删除按钮的表格。按下删除后,它会转到应该删除记录的第二页。但事实并非如此。下面是我正在使用的代码。

PS:代码改编自我不久前通过谷歌找到的一个教程。

删除_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> &euro; " . $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);
?>

删除.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!");
}
?>

感谢所有愿意提供帮助的人!

4

1 回答 1

1

以下答案来自用户 Andrewsi。这个答案发布在评论中。

DELETE 的语法是DELETE FROM- 您需要删除*

于 2013-11-01T16:52:32.417 回答