使用会话中的用户ID更新用户信息

时间:2018-12-06 12:41:01

标签: php mysql session user-controls profile

我有一个项目,用户可以在其中编辑自己的个人资料。 我目前有一个登录/注册页面。现在是时候进行用户编辑页面了。 该网站可用于会话,因此,只要他们回来,他们就会在导航栏中看到我的个人资料。

我已经用PHP测试了所有内容,以更新帐户。

我目前有2个文件用于更新配置文件脚本。

1 is the profile.php, the other in includes/update.inc.php

includes/login.inc.php中,我已经分配了一个会话。

          if ($pwdCheck == false) {
        header("Location: ../index.php?error=wrongpassword");
        exit();
      }
      else if ($pwdCheck == true) {
        session_start();
        $_SESSION['userId'] = $row['idUsers'];
        $_SESSION['userUid'] = $row['uidUsers'];

        header("Location: ../index.php?logging=succes");
        exit();

是的,来自 includes / login.inc.php

现在,当您转到您的个人资料时,它会检查if $_SESSION['userId'] == true.

现在以下:

这是我的profile.php

    <?php
     require "header.php";
      require "includes/dbh.inc.php";
         $sessionkk = $_SESSION['userId'];
         error_reporting(E_ALL); ini_set('display_errors', 1);

      $query = "SELECT idUsers, uidUsers, emailUsers,pwdUsers,Voornaam,Tussenvoegsel,Achternaam,Schooljaar,School,Opleiding,Niveau,Recht,Taal 
 , 
 printerA,printerB,printerC FROM users WHERE idUsers = '$sessionkk'";
   $result = $conn->query($query) or die($conn->error);

   if(mysqli_num_rows($result) > 0){
   while ($row = mysqli_fetch_assoc($result)){
   $id = $row['idUsers'];
   $username = $row['uidUsers'];
   $email = $row['emailUsers'];
   $password = $row['pwdUsers'];
   $voornaam = $row['Voornaam'];
   $tussenvoegsel = $row['Tussenvoegsel'];
   $achternaam = $row['Achternaam'];
   $Schooljaar = $row['Schooljaar'];
   $School = $row['School'];
   $Opleiding = $row['Opleiding'];
   $niveau = $row['Niveau'];
   $Taal = $row['Taal'];
   $printera = $row['printerA'];
   $printerb = $row['printerB'];
   $printerc = $row['printerC'];

}
}





?>

  <div class="adminform">
      <h2>gegevens aanpassen</h2><br/>
          <form action="includes/update.inc.php" method="POST">
              <input type="text" name="username" placeholder="Username" 
value=" 
<?php if(isset($_GET['username'])){echo $_GET['username'];}?>"><br/><br/>
          <input type="text" name="email" placeholder="E-mail" value="<?php 
if(isset($_GET['email'])){echo $_GET['email'];}?>"><br/><br/>
          <input type="text" name="" placeholder="Schooljaar" value="<?php 
if(isset($_GET['Schooljaar'])){echo $_GET['Schooljaar'];}?>"><br/><br/>
          <input type="text" name="email" placeholder="E-mail" value="<?php 
    if(isset($_GET['School'])){echo $_GET['School'];}?>"><br/><br/>
          <button type="submit" name="adminupdate">Aanpassen</button>
      </form>
      <?php
        echo "" . $id;

       ?>
  </div>
 <?php

 ?> 

我在这里总结了一切。表单名称等

您还可以看到我如何制作$sessionkk = $_SESSION['userId'];

$ sessionkk与

一起使用

这是include / update.inc.php

    <?php
    session_start();
       require "dbh.inc.php";


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

     $sql = "UPDATE users SET  uidUsers= '?', emailUsers = '?', Schooljaar = 
 '?', 
     School = '?' WHERE idUsers = '.$sessionkk.'";
                 $stmt = mysqli_stmt_init($conn);
                 if(!mysqli_stmt_prepare($stmt, $sql)){
                       header("Location: ../profile.php?error=sqlerror");
                      exit();
                } else{
                    mysqli_stmt_bind_param($stmt, "ssss", $username, $email, 
          $Schooljaar, $School);
                    mysqli_stmt_execute($stmt);

                    header("Location: ../profile.php?update=succes");
                    exit();
                }
              }
     ?>

我只用数据库中的ID尝试了$ sql查询,所以就像这样:

$sql = "UPDATE users SET  uidUsers= '?', emailUsers = '?', Schooljaar = '?', 
School = '?' WHERE idUsers = '4'";

,这将起作用。 但是我想从登录的用户那里获取ID。 抱歉,代码太乱了,我不知道如何在此处正确上传代码。

谢谢

0 个答案:

没有答案