如何添加删除链接

时间:2015-01-28 09:20:41

标签: php html mysql pdo mysqli

我正在尝试在“操作”列下添加删除链接按钮,该按钮会在单击时删除条目。我已经创建了delete.php文件但是我没有成功创建一个链接它的URL。 下面的代码从我的数据库输出'收据'表中的数据....是否可能?我该怎么办?

<?Php
require "config.php";           

$page_name="currentout.php";  
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}


$eu = ($start - 0); 
$limit = 10;                                 
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 

$nume = $dbo->query("select count(id) from receipt")->fetchColumn();


echo "<TABLE class='t1'>";
echo  "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>";


$query=" SELECT * FROM receipt  limit $eu, $limit ";


foreach ($dbo->query($query) as $row) {

@$m=$i%2;
@$i=$i+1;   
echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td></tr>";
}
echo "</table>";

if($nume > $limit ){ 
echo "<table align = 'center' width='50%'><tr><td  align='left' width='30%'>";

if($back >=0) { 
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; 
} 

echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";}        
$l=$l+1;
}


echo "</td><td  align='right' width='30%'>";

if($this1 < $nume) { 
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td></tr></table>";

} 
?>

1 个答案:

答案 0 :(得分:0)

更改此行

echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td></tr>";

echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$id'>delete</a></td></tr>";

创建新文件delete.php

<?php
$sql = "DELETE FROM receipt  WHERE ID=  :ID";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':ID', $_GET['id'), PDO::PARAM_INT);  
$stmt->execute();
header('location: index.php');
?>