有人可以弄清楚为什么我会删除'链接不起作用? 这是currentout.php的代码,它有一个删除链接
<?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><td><a href='delete.php?id=$id'>delete</a></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>";
}
?>
这是我的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');
?>
我需要用户在点击“删除”条目时能够删除条目。链接。
编辑。这是HTML输出
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: ;
background-color: #F0F0F0;
}
.style1 {
font-size: 14px;
font-weight: bold;
}
.style2 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
<link href="../styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style3 {font-size: 18px}
-->
</style>
</head>
<body>
<p> </p>
<table width="781" height="48" border="0" align="center">
<tr>
<td><h3 align="right"> <a href="logout.php">Logout</a> </h3></td>
</tr>
<tr>
<td><h3 align="left"> <span class="usrname">admin </span> </h3></td>
</tr>
</table>
<table width="781" height="48" border="0" align="center">
<tr>
<td width="186"><a href="../receipt/receiptt.php">Book New</a> </td>
<td width="152"><a href="../current in/currentIn.php">Current in </a></td>
<td width="34"><div align="center"><a href="../out/currentout.php"></a> </div></td>
</tr>
</table>
<table width="781" height="190" align="center">
<tr>
<td height="61" colspan="4"><div align="center" class="style2 style3">CHECK OUT </div>
<span class="style1">There are currently tourists in the park </span></td>
</tr>
<br />
<b>Notice</b>: Undefined index: start in <b>C:\xampp\htdocs\table\out\currentout.php</b> on line <b>73</b><br />
<TABLE class='t1'><tr><th>ID</th><th>Name</th><th>Class</th><th>Mark</th><th>Action</th><th>Action</th><th>Action</th></tr><br />
<b>Notice</b>: Undefined variable: row in <b>C:\xampp\htdocs\table\out\currentout.php</b> on line <b>98</b><br />
<tr class='r0'><td>10</td><td>Sam</td><td>478562</td><td>450</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r1'><td>9</td><td>Jim Jones</td><td>72548623</td><td>900</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r0'><td>6</td><td> Jane C.P.L</td><td>64849</td><td>560</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r1'><td>7</td><td> maryanne</td><td>31356664</td><td>1400</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r0'><td>8</td><td> Jim Okoth</td><td>1028587</td><td>1000</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r1'><td>11</td><td>joe</td><td>554</td><td>48</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r0'><td>12</td><td>john mugambi</td><td>725485632</td><td>400</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r1'><td>13</td><td>ryan</td><td>1558</td><td>200</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r0'><td>14</td><td>James </td><td>5563</td><td>500</td><td><a href='delete.php?id='>delete</a></td></tr><tr class='r1'><td>15</td><td>mike</td><td>2584</td><td>45</td><td><a href='delete.php?id='>delete</a></td></tr></table><table align = 'center' width='50%'><tr><td align='left' width='30%'></td><td align=center width='30%'><font face='Verdana' size='4' color=red>1</font> <a href='currentout.php?start=10'><font face='Verdana' size='2'>2</font></a> <a href='currentout.php?start=20'><font face='Verdana' size='2'>3</font></a> </td><td align='right' width='30%'><a href='currentout.php?start=10'><font face='Verdana' size='2'>NEXT</font></a></td></tr></table>
<p align='center'><a href='../login/usermenu.php'><strong>Home </strong></a></p>
</div>
</body>
</html>
答案 0 :(得分:2)
更改以下行
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>";
到
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=$row[id]>delete</a></td></tr>";
请注意,用于删除数据库中某行的代码非常不安全。每个人都可以去delete.php?id = 1并删除第1行