2013-11-01 36 views
0

我正在使用2頁。在一頁上它會生成一個包含記錄和刪除按鈕的表格。按刪除後,進入第二頁,該頁面應刪除該記錄。但事實並非如此。以下是我正在使用的代碼。通過記錄生成的表從mysql中刪除行

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> &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); 
?> 

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

謝謝大家誰願意幫助!

+2

爲DELETE的語法是'DELETE FROM' - 你需要用刪除'*' – andrewsi

+2

不要**不**做刪除操作GET查詢:http://thedailywtf.com/Articles/The_Spider_of_Doom.aspx –

+1

@andrewski謝謝你的答案。這是對的錢。它效果很好。你介意把它作爲答案嗎?這樣我可以選擇它作爲正確的答案。 – HennySmafter

回答

1

以下答案來自用戶Andrewsi。這個答案發布在評論中。

的DELETE語法是DELETE FROM - 你需要刪除*