提交时重新加载其他页面

时间:2017-08-01 18:12:04

标签: javascript php html css

我目前正在制作rota,其中一个页面是更新已登录帐户的名字和姓氏。

网页分为标题(包括其他页面和登录)正文(内容取决于您所在的页面)和页脚(保留当前时间)。

当帐户登录时,他们可以选择退出并显示姓名。当他们登录帐户并更改名字或姓氏并提交时,它会在数据库中更改,但为了使其显示在标题中“您以Jack Smith身份登录”,您需要退出帐户并重新登录。

我猜测原因是因为每个包都加载了标题,并且在更新数据库时不会刷新。我已经在网上看了,我已经尝试了action =“window.location.reload()”但似乎没有用。

以下是我的标题和帐户设置页面的代码,以及数据库更改。感谢所有帮助。

HEADER
    <?php
    session_start();
    date_default_timezone_set('Europe/London');
?>

<!DOCTYPE html>
    <html>
        <head>
        </head>
    <meta charset="utf-8">
        <title> Egress Lunch Rota</title>
    <link rel="stylesheet" type="text/css" href="styles.css">

<script type="text/javascript" src="javascript.js"></script>

<div id="head">
    <table id="span">
        <tr>
            <td id="test">
                <table id="padding2">
                    <tr class="padding">
                            <td class="padding"><a href="index.php">Home</a></td>
                            <td class="padding"><a href="signup.php">Sign up</a></td>
                         <td class="padding"><a href="account.php">Account</a></td>
                    </tr>
                </table>
            </td>
            <td class="info">
                <?php
                if (isset($_SESSION['first'])) {
                    echo '<form action="includes/logout.inc.php" method="POST">
                    <button type="submit" name="submit">Logout</button>
                    </form>';
                } else{ 
                    echo '<form action="includes/login.inc.php" method="POST">
                    <input type="text" name="uid" placeholder="Username">
                    <input type="password" name="pwd" placeholder="Password">
                    <button type="submit" name="submit">Log In</button>
                </form>';
                }

                ?>


                    <div id="signup">
        <?php
            if (isset($_SESSION['first']) && isset($_SESSION['last'])) {
                echo "You are signed in as: " . $_SESSION['first']. " ";
                echo $_SESSION['last'];

            } else{
                echo "<br>";
            }
        ?>
    </div>


            </td>
        </tr>
    </table>
</div>


ACCOUNT HTML PAGE
    </<?php 
    include 'header.php';
 ?>
<body onload="startTime()">

        <div class="accounttitle">
            <b> Change Account Settings</b>
        </div>

    <div class="accountcontent">

            <b>Personal information</b><br>
            <form action="includes/account.inc.php" action="includes/header.inc.php" method="POST">
            <div class="inputs">Firstname:</div> <div class="test"> <input type="text" name="first" placeholder="Firstname" class="size"></div>
            <div class="inputs">Secondname:</div> <div class="test">  <input type="text" name="last" placeholder="Lastname" class="size"></div>

            <div><button onclick="location.reload()" type="submit" name="submit" class="button">Submit</button></div>
            </form>
        </div>
    </div>

    <div class="accountcontent">
        <div>
            <b>Password</b><br>
            <form action="includes/account.inc.php" method="POST">
            <div class="inputs">  Current Password:</div> <div class="test"> <input type="password" name="cpassword" placeholder="Current Password" class="size"></div>
            <div class="inputs">  New Password:</div> <div class="test"> <input type="password" name="npassword" placeholder="New Password" class="size"> </div>
            <div class="inputs"> Confirm new Password: </div> <div class="test"> <input type="password" name="cnpassword" placeholder="Confirm Password" class="size"> </div>
            <div><button type="submit" name="submit1" class="button">Submit</button></div>
        </div>
    </div>

    <div class="accountcontent">
        <div>
            <b>Security questions</b><br>

            First Security Question:
            <form action="includes/account.inc.php" method="POST">
            <div class="tests">
            <select name="qone">
                <option value="Where did you go for your first holiday?">Where did you go for your first holiday?</option>
                <option value="What make was your first car?">What make was your first car?</option>
                <option value="Where did you spend your honeymoon?">Where did you spend your honeymoon?</option>
                <option value="In what city do you work?">In what city do you work?</option>
                <option value="What is your least favourite job?">What is your least favourite job?</option>
                <option value="What is the name of your first firend?">What is the name of your first friend?</option>
                </select>
                </div>

            First Answer: <div class="tests"> <input type="text" name="aone" placeholder="#1 Answer" class="size"><br> </div>

            Second Security Question:
            <div class="tests">
            <select name="qtwo">
                <option value="Where did you go for your first holiday?">Where did you go for your first holiday?</option>
                <option value="What make was your first car?">What make was your first car?</option>
                <option value="Where did you spend your honeymoon?">Where did you spend your honeymoon?</option>
                <option value="In what city do you work?">In what city do you work?</option>
                <option value="What is your least favourite job?">What is your least favourite job?</option>
                <option value="What is the name of your first firend?">What is the name of your first friend?</option>
                </select>
                </div>


            Second Answer: <div class="tests"> <input type="text" name="atwo" placeholder="#2 Answer" class="size"><br></div>
            <div><button type="submit" name="submit2" class="button">Submit</button></div>
            </form>

        </div>
    </div>


<?php 
    include 'footer.php';
 ?>


ACCOUNT BACK END
<?php
session_start();

if (isset($_POST['submit'])) {

    include_once '../dbh.php';

    $first = mysqli_real_escape_string($conn, $_POST['first']);
    $last = mysqli_real_escape_string($conn, $_POST['last']);

    //Query
    $sql = "SELECT * FROM users1";
    $sql1 = "SELECT * FROM lunch";
    $result = mysqli_query($conn, $sql);
    $result1 = mysqli_query($conn, $sql1);

        //Error handlers
        if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)){
        header("Location: ../account.php?account=invalid");
        exit();
        }   else{
                        $sql = "UPDATE users1 SET first = '$_POST[first]', last = '$_POST[last]' WHERE id = '$_SESSION[id]'";
                        $sql1 = "UPDATE lunch SET firstname = '$_POST[first]', secondname = '$_POST[last]' WHERE tid = '$_SESSION[id]'";
                        mysqli_query($conn, $sql);
                        mysqli_query($conn, $sql1);
                        header("Location: ../account.php?account=success");
                        exit();
                        }
}

0 个答案:

没有答案