创建了一个用户登录页面。我可以在哪里看到哪个用户已登录。但我无法从数据库中删除用户。我正在使用 PDO 连接数据库。这是我删除用户的方法:
public function delete($user_name)
{
$sql = $this->connection()->prepare("delete from online where user_name = :user_name");
$sql->bindValue(':user_name', $user_name, PDO::PARAM_STR);
$sql->execute();
return $sql;
}
这是我的 HTML 代码:
if(isset($_POST['submit'])){
$user_name = isset($_POST['user_name']);
print_r($user_name);
//call delete method to delete the user from database
$database->delete($user_name);
}
<form action="" method="post">
<?php
foreach($rows as $row){
$time = $row['time_out'];
echo "<input type='text' value='$row[user_name]' name='user_name'>
<input type='text' value=' $row[course]' >
<input type='text' value=' $time '>
<input type='hidden' value='$row[user_name]' name='user_name'>
<input type='submit' value='delete' name='submit'><br>";
}
?>
</form>