在会话中使用用户id更新用户信息

91zkwejq  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(305)

我有一个项目,用户可以编辑自己的个人资料。我目前有一个登录/注册页面。现在是用户编辑页面的时候了。该网站与会话一起工作,因此,每当他们回来时,他们都会在导航栏中看到我的个人资料。
我已经用php测试了所有的东西,以更新帐户。
我目前有两个文件,其中更新配置文件脚本的工作。 1 is the profile.php, the other in includes/update.inc.phpincludes/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。对不起,代码是如此混乱,我不知道如何上传代码在这里正确。
谢谢您

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题