更新Userprofile

时间:2018-04-05 09:17:45

标签: php sql session

我有一个session.php和一个welcome.php页面。我有我的userprofile。

我正在尝试更新电子邮件字段。

当我更改我的电子邮件地址并按下更新按钮时,我得到echo Update Successful,但它没有更新。我认为它仍然具有会话的旧价值,我需要清除它。

session.php文件:

<?php
include('connection.php');
session_start();

$user_check = $_SESSION['login_user'];


$ses_sql = mysqli_query($db,"select * from clients where email = '$user_check'");

$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

$_SESSION['email']= $row['email'];
$_SESSION['username']= $row['username'];
$_SESSION['firstname']= $row['firstname'];
$_SESSION['lastname']= $row['lastname'];
$_SESSION['birthdate']= $row['birthdate'];
$_SESSION['street']= $row['street'];
$_SESSION['streetnr']= $row['streetnr'];
$_SESSION['city']= $row['city'];
$_SESSION['plzz']= $row['plzz'];
if(!isset($_SESSION['login_user'])){
  header("

location:http://localhost:81/Left_over_youth_website/pages/login.php");
    }
?>

的welcome.php:

    <?php
     include("../php/session.php");
    ?>
 <div>
                    <div class="col-md-9">
                        <div class="imagepageback">
                            <div class="card">
                                <div class="profilimage"></div>
                                <hr class="verticalline">    
                                      <?php                                 
                                        $sql = "UPDATE clients SET emaill = $_SESSION WHERE email = $user_check";
                                        $update = mysqli_query($db, $sql);
                                        if($update){
                                            echo("update sucessful");
                                            $_SESSION["emaill"] = $email_session;
                                        }
                                        ?>                 
                                    <form class="form" action="" method="post">
                                    <input id="usernamee" class="usernamee" type="text" name="username" value="<?php echo $_SESSION['username']; ?>" readonly>
                                    <input id="emaill" class="emaill" type="text" name="email" value="<?php echo $_SESSION['email']; ?>" readonly>
                                    <input id="firstnamee" class="firstnamee" type="text" name="firstname" value="<?php echo $_SESSION['firstname']; ?>" readonly>
                                    <input id="lastnamee" class="lastnamee" type="text" name="lastname" value="<?php echo $_SESSION['lastname']; ?>" readonly>
                                    <input id="birthdatee" class="birthdatee" type="text" name="birthdate" value="<?php echo $SESSION['birthdate']; ?>" readonly>
                                    <div>
                                        <input id="streett" class="streett" type="text" name="street" value="<?php echo $_SESSION['street']; ?>" readonly>
                                        <input id="nrr" class="nrr" type="text" name="streetnr" value="<?php echo $_SESSION['streetnr']; ?>" readonly>
                                    </div>
                                    <div>
                                        <input id="cityy" class="cityy" type="text" name="city" value="<?php echo $_SESSION['city']; ?>" readonly>
                                        <input id="plzz" class="plzz" type="text" name="plzz" value="<?php echo $_SESSION['plzz']; ?>" readonly>
                                    </div>
                                    <a href="#" class="editprofilelink" id="editprofilelink"  onclick="editable(); showbt()"; >Edit Profile</a>
                                    <a href="changepd.html" class="editpasswordlink">Change Password</a>
                                    <input hidden id="btupdate" type="submit" name="btupdate" value="Update">   
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

2 个答案:

答案 0 :(得分:1)

在更新查询中回显'更新成功'。 请尝试以下方法。

在welcome.php中:

<?php     
    if(isset($_POST['btupdate'])){ 
        $email = $_REQUEST['email'];             
        $sql = "UPDATE clients SET emaill = '$email' WHERE email = '$email_session'";

        $update = mysqli_query($db, $sql);
if($update)
{
     echo("update successful");
}

?>

答案 1 :(得分:0)

您对此代码有致命错误:

<?php                                 
$email = "SELECT * From Clients";
$sql = "UPDATE clients". "SET emaill = $email". "WHERE email = $email_session";
if(isset($_POST['btupdate'])){
    $update = mysqli_query($db, $sql);
    echo("update sucessful");
}
?>

此部分(“UPDATE clients”。“SET emaill = $ email”。“WHERE email = $ email_session”)返回此字符串“UPDATE clientsSET emaill = example@example.comWHERE email = example2@example.com

试试这个:

$sql="UPDATE clients SET emaill = $email WHERE email = $email_session"

使用concatin时要小心,不会为你增加任何空间。

更改后,您不会更改$ _SESSION [“email”]。你必须添加$ _SESSION [“email”] = $ email;

 <?php                                 
$email = "SELECT * From Clients";
$sql = "UPDATE clients SET emaill = $email WHERE email = $email_session";
$update = mysqli_query($db, $sql);
if($update){
    echo("update sucessful");
}
?>