嘿,我是PHP的新手,需要从MYSQL TABLE中删除我的用户名驻留在html表中的记录! 我将mysql表数据提取到html表中的代码是:
while($data=mysqli_fetch_array($result)){
$count+=1;
echo "<tr>";
echo "<td>";
echo "<p>";
echo $count;
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['myusername'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['logincount'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['signindate'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo $data['signupdate'];
echo "</p>";
echo "</td>";
echo "<td>";
echo "<p>";
echo "<a href='deluser.php?id=" . $data['myusername'] . "'>Del</a>"; //here i want to use this link to delete a user
echo "</p>";
echo "</td>";
echo "</tr>";
}
我的deluser.php是:
<?php
//$user=$_GET['myusername'];
$isConnected=mysqli_connect('localhost','root','','mydb');
if($isConnected){
if (isset($_GET["myusername"])) {
$query = "DELETE FROM users WHERE myusername = " . $_GET["myusername"];
$result = mysqli_query($con, $query);
// Check the result and post confirm message
if(!$result){
echo 'error'.mysqli_error($isConnected);
}
else{
echo 'success';
}
}
}
?>
假设已经设置了连接,然后我想使用通配符删除记录,即html table的myusername ='value'!
问题在于没有任何东西向我显示,也没有错误也没有成功,所以我做错了什么可以有人帮助我!
答案 0 :(得分:0)
$result = mysqli_query($con, $query);
mysqli_query()
函数第一个参数必须是连接链接,为什么使用$con
变量?您在$isConnected
变量中与数据库的连接链接。试试这个:
$result = mysqli_query($isConnected, $query);
如果您的myusername
值是字符串,则需要将此值用单引号:
$query = "DELETE FROM users WHERE myusername = '" . $_GET["myusername"] . "'";
对于数据库中的更新信息,您需要使用POST
方法,GET
方法适用于所需信息但不适用于更新,这是不安全的。
答案 1 :(得分:0)
看起来您设置的查询不正确。应该是:
$query = "DELETE FROM users WHERE myusername = '" . $_GET["myusername"] . "'";