dpd3447 2018-12-06 12:41
浏览 79

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

I have a project, where users can edit their own profile. I currently have a login/register page. Now its time for a user-edit page. The site works with sessions so, whenever they come back they see myprofile in the navbar.

I've tested everything in PHP, to update the account.

I currently have 2 files where the update-profile scripts works with.

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

In includes/login.inc.php I have already assigned a session.

          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();

So yeah that was from the includes/login.inc.php.

Now when u go to your profile it checks if $_SESSION['userId'] == true.

Now the following:

This is my 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

 ?> 

Here i conclude everything. The formname etc etc.

You can also see how i make a $sessionkk = $_SESSION['userId'];

The $sessionkk works with the

Here is the 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();
                }
              }
     ?>

I tried the $sql query with just the ID from the database so it would be like this:

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

and this would work. But i want to grab the id from the user who is logged in. Sorry that the code is so messy, i dont know how to upload code correctly here.

Thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据