停用帐户无效

时间:2016-02-25 20:58:04

标签: php html session mysqli

deactivate_myaccount.php中的代码运行一次然后在顶部出现错误 - “注意:会话已经启动 - 忽略C:\ xampp \ htdocs \ includes \ includes \ header-inc中的session_start()第2行的.php“。此外,此代码应该将DB中的“已关闭”字段更改为“是”,以便此人无法登录,但这不会发生。我相信会议正在进行中。当我使用相同的详细信息重新登录时,系统允许我登录,然后当我选择“停用帐户”按钮时,它只是说“您必须登录才能查看此页面!”并且不会显示表单以供我停用。

Deactivate_myaccount.php
    <?php
    session_start();
    if (!isset($_SESSION["user_login"])) {
       header("Location: sign_up.php");
    } else {
          $username = $_SESSION["user_login"];
    }


    include ("includes/header-inc.php");

    ?>

    <h2> Deactivate Account: </h2>

    <?php
    //Taking the user back
    $email = "";
    if ($email) {
        if(isset($_POST['no'])){
            header ("Location: includes/profile_student.php");
            }
    if (isset($_POST['yes'])){
        $deactivate_acc = mysqli_query("UPDATE users SET closed = 'yes' WHERE email = '$email'");
        echo "You account has now been deactivated! Sorry to see you leaving MYASTONSPACE";
        session_destroy();
    }
    }
    else {

        die ("You must be logged in to view this page!");   

        }

    ?>

<br/>



     <center>
        <form action="deactivate_myaccount.php" method = "POST" >
        Are you sure you want to deactivate your account? <br>
        <input type="submit" name = "no" value="No">
        <input type="submit" name = "yes" value="Yes">
        </form>
        </center>

<?php
include ("includes/footer-inc.php")
?>

profile_student.php

     <?php
        session_start();
        if (!isset($_SESSION["user_login"])) {
           header("Location: sign_up.php");
        } else {
              $username = $_SESSION["user_login"];
        }
        include ("includes/connect.php");
        ?>

<!doctype html>
<html>
<head>
    <title>Student Profile</title>

    <link rel="stylesheet" type="text/css" href="css/profile_student.css">

</head>

<body>

<div class="logo" style="margin-left: 750px;"><a href="Index.html"><img class="logo" src="images/logo.png"/></a></div>
<li><a href="/includes/logout.php">Log Out</a></li>
    </div>
    <hr>

    <div class = "main_menu_buttons"  style="margin-left: 25px;">
                    <p> Home | Undergraduate Information | Post-Grad Information | International Students | Contact Us  </p>





     <div class = "User_options">
            <table>
                <tr>
                    <td>
                         Personal information  
                        <br>
                        Favourite Properties
                        <br>
                         Upload Picture:
                        <br>
                         Messages 
                        <br>
                         <a href="includes/deactivate_myaccount.php"> Deactivate Account </a>
                  </td>
             </tr>
            </table>
            </div>

2 个答案:

答案 0 :(得分:0)

如果您的电子邮件始终是$email = '',并且它与任何内容都不匹配,那么它只是在进行更新:

UPDATE users SET closed = 'yes' WHERE email = ''

可能会也可能不会更新相关用户。

如果您决定填充...请逃避它;或使用PDO /参数化查询。

答案 1 :(得分:0)

根据错误消息,您在includes / header-inc.php文件中调用session_start()。执行Deactivate_myaccount.php时,将打开一个新会话,然后包含标头。由于会话已经打开,header-inc.php无法再次打开它,因此忽略此函数调用。

这仅仅是一个通知,应该修复原因以符合常见的编码样式,但它不应该影响应用程序的功能。我看到其他人已经帮助你解决了这个功能问题。