使用PHP变量从MySQL表中删除条目
我很确定这个问题已经被问过很多次了,我已经在网上搜索过了,仍然无法找到解决这个问题的方法 以下是代码(我知道它不是注射证明): 显示表中所有条目的步骤使用PHP变量从MySQL表中删除条目,php,mysql,Php,Mysql,我很确定这个问题已经被问过很多次了,我已经在网上搜索过了,仍然无法找到解决这个问题的方法 以下是代码(我知道它不是注射证明): 显示表中所有条目的步骤 <?php $query="SELECT * FROM testimony"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { ?> <div> <form name="testimonial" action="admin
<?php
$query="SELECT * FROM testimony";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<div>
<form name="testimonial" action="admintestimony.php" method="post">
<table border="0">
<tr>
<td>Username:</td>
<td></td>
<td><input type="text" name="testyname" value='<?php echo $row[0];?>' readonly></td>
</tr>
<tr>
<td>Testimony:</td>
<td></td>
<td><textarea name="txttesty" cols="50" rows="10" readonly><?php echo $row[1];?></textarea></td>
</tr>
<tr>
<td><input type="submit" name="approve" value="Approve"></td>
<td></td>
<td><input type="submit" name="reject" value="Reject"></td>
</tr>
</table>
</form>
</div>
<?php
}
?>
用户名:
检查是否按了“批准”或“拒绝”
<?php
session_start();
include('connection.php');
$testyname=$_POST['testyname'];
if (isset($_POST['approve']))
{
header("location:testimonyapproved.php");
}
else if (isset($_POST['reject']))
{
header("location:reject.php");
}
?>
<?php
session_start();
$testyname=$_POST['testyname'];
include('connection.php');
mysql_query("SELECT * FROM testimony");
mysql_query("DELETE FROM 'transaction' WHERE 'transaction' 'name' = $testyname");
header("location:testimonyrejected.php");
?>
如果按下“拒绝”
<?php
session_start();
include('connection.php');
$testyname=$_POST['testyname'];
if (isset($_POST['approve']))
{
header("location:testimonyapproved.php");
}
else if (isset($_POST['reject']))
{
header("location:reject.php");
}
?>
<?php
session_start();
$testyname=$_POST['testyname'];
include('connection.php');
mysql_query("SELECT * FROM testimony");
mysql_query("DELETE FROM 'transaction' WHERE 'transaction' 'name' = $testyname");
header("location:testimonyrejected.php");
?>
这是您的SQL
DELETE FROM `transaction` where `name` = $testyname
可能工作得更好您的SQL格式错误(引号放在错误的地方)。
我在这段改进的代码中添加了一些注释,请查看
mysql_query("SELECT * FROM testimony"); //this line is useless and you can delete it
mysql_query("DELETE FROM transaction WHERE name = '".$testyname."'"); //this line contained wrong syntax
请注意,新版本的PHP中不推荐使用mysql_uu函数。查看有关此主题的更多信息
另外,您可能希望阻止$testmyname
变量中的SQL注入。将帮助您进行tat。这很容易被注射。清理输入并研究使用mysqli_*函数而不是不推荐使用的mysql_*函数。谢谢,但是条目仍然存在,它不会删除。