使用会话从数据库中删除($ _SESSION)

时间:2017-07-02 08:51:17

标签: php mysql

我有一个想要从数据库中删除的记录。到目前为止,我已经能够保存到mysql数据库,现在我有几行中的几个信息,现在假设信息不是所需的信息,我想从数据库中删除它。这就是我想在这里实现的目标

我试过这个

<?php
session_start();
require_once('inc/config.php');
if(!isset($_SESSION['username'])){
    header('Location: signon.php');
}
?>

<?php
require_once('inc/config.php');
$con = mysqli_connect($host, $user, $pass, $db) or die ('Cannot connect: '.mysqli_error());
$sql = "SELECT * FROM education_info WHERE username = '" . $_SESSION['username'] . "'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result);
$id = $row['id'];
$username = $row['username'];

$sql2 = "DELETE FROM education_info WHERE id = $id" ;
$result = mysqli_query($con,$sql);
mysqli_close($con);

header("Refresh:0; url=EDWE.php");
?>

只有信息仍然存在于数据库中,如果不需要,如何完全删除它?

1 个答案:

答案 0 :(得分:0)

执行删除查询时传递错误的变量:

$sql2 = "DELETE FROM education_info WHERE id = $id" ;
$result = mysqli_query($con,$sql2); //<---pass $sql2