Skip to content
Advertisement

User updated information not showing

i have problem in my php which is user updated data is not showing in the page, it shows only the previous data and not the updated data, but the information already updated in database

This is my updateForm.php:

 <?php
 session_start();

 $std = $_SESSION;
 ?>

 <!DOCTYPE html>
 <html>
 <head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Profile  | MyMerit</title>
<!-- Fonts-->
<link href="https://fonts.googleapis.com/css? 
 family=Archivo+Narrow:300,400,700%7CMontserrat:300,400,500,600,700,800,900" rel="stylesheet">
<link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="plugins/ps-icon/style.css">
<!-- CSS Library-->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" href="plugins/bootstrap/dist/css/bootstrap.min.css">  
</head>
<div class="header--sidebar"></div>
<header class="header">
  <div class="header__top">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-6 col-md-8 col-sm-6 col-xs-12">
          <p>Welcome to MyMerit</p>
        </div>
        <div class="col-lg-6 col-md-3 col-sm-6 col-xs-12">
          <div class="header__actions"><a href="stdLogin.php"><i class="fas fa-sign-out-alt"> 
  </i>Back</a></div>
        </div>
      </div>
    </div>
  </div>
</header>
<body>
<div class="col-lg-4 col-lg-offset-4">
  <div class="page-header">  
    <h2>Student Profile Update</h2>
  </div>
  <form action="stdUpdateData.php" method="POST">
    <div class="form-group">
      <div class="input-group col-xs-15">
        <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
        <input type="text" class="form-control" name="stdName" placeholder="Username" required>
      </div>
    </div>
    <div class="form-group"> 
      <div class="input-group col-xs-15">
        <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
        <input type="text" class="form-control" name="stdMatric" placeholder="Matric No" required>
      </div>
    </div>

      <div class="form-group"> 
      <div class="input-group col-xs-15">
        <label for="faculty">Faculty:&nbsp&nbsp&nbsp</label>
          <select name="stdFaculty" id="faculty">
          <option value="fkom">FKOM</option>
          <option value="fkasa">FKASA</option>
          <option value="ftek">FTEK</option>
          <option value="fim">FIM</option>
          <option value="fist">FIST</option>
    </select>
      </div>
    </div>

    <div class="form-group">
      <div class="input-group col-xs-15">
         <span class="input-group-addon"><i class="glyphicon glyphicon-phone"></i></span>
        <input type="text" class="form-control" name="stdPhone" placeholder="Phone Number" required>
      </div>
    </div>
    <div class="form-group">
      <div class="input-group col-xs-15">
        <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
        <input type="password" class="form-control" name="stdPwd" placeholder="Password" required>
      </div>
    </div>
    <div class="btn-group">
      <button type="submit" class="btn btn-primary">Update Profile</button>
    </div>
  </form>
</div>

This is my stdUpdateData.php, where the sql database process the update data:

    <?php
   require('dbconfig.php');

session_start();

// Store the $_SESSION in a more handy variable
$stdID = $_SESSION['id'];

$stdName = $_POST['stdName'];
$stdMatric = $_POST['stdMatric'];
$stdFaculty= $_POST['stdFaculty'];
$stdPhone = $_POST['stdPhone'];
$stdPwd = $_POST['stdPwd'];

$sql = "UPDATE student SET stdName = '$stdName', stdMatric = '$stdMatric', stdFaculty = '$stdFaculty', stdPhone = '$stdPhone', stdPwd = '$stdPwd' WHERE id = '$stdID'" ;

if (mysqli_query($mysqli,$sql)) {
    //header("refresh:0; url=stdUpdateForm.php");
    //echo '<script language="javascript">';
    
   echo "<script>alert('Data successfully updated!');
        window.location = 'stdProfile.php?id=".$_SESSION['id']."';</script>";
    //echo 'alert("Data update successfully!")';
    //echo '</script>';
} 
else {
    header("refresh:0; url=stdUpdateForm.php");
    echo '<script language="javascript">';
    echo 'alert("Data update fail!")';
    echo '</script>';
}
mysqli_close($mysqli);
?>

This is the studentProfile.php,when user register for the first time it show the information correctly, but after user update their information it only updated in database and not updated in this form even i refreshed it, still doesnt show the updated information:

    <?php
session_start();

$std = $_SESSION;
?>
 <!DOCTYPE html>
 <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="images/logo.jpg">
<title>Profile | Student MyMerit</title>
<link rel="stylesheet" type="text/css" href="css/all.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://use.fontawesome.com/3cc6771f24.js"></script>
</head>
<body>

      
<h3 style="margin-left: 1em; margin-top: 1em;text-decoration: underline;">Student Profile</h3>
  <div style="margin-left: 1em;">
      <div class="form">    
      <div class="row">
        <div class="col-xs-4">
        <label>Student Name</label>
        <input type="text" class="form-control" name="stdName" value="<?=$std['stdName']?>" readonly>
      </div>
      </div>
      <br />
      <div class="row">
        <div class="col-xs-4">
          <label>Student Matric</label>
          <input type="text" class="form-control" name="stdMatric" value="<?=$std['stdMatric']?>" 
   readonly>
        </div>
      </div>
      <br>
      <div class="row">
        <div class="col-xs-4">
          <label>Student Faculty</label>
           <input type="text" class="form-control" name="stdFaculty" value="<?=$std['stdFaculty']?>" 
   readonly>
         
        </div>
      </div>
      <br />
      <div class="row">
        <div class="col-xs-4">
          <label>Student Phone</label>
          <input type="text" class="form-control" name="stdPhone" value="<?=$std['stdPhone']?>" 
   readonly>
        </div>
      </div>
      <br />
      <button type="button" class="btn btn-danger" onclick="location.href='stdUpdateForm.php?id=<? 
       =$_SESSION['id']?>'">Edit</button>
     
     
    </div>
</div>

Advertisement

Answer

I assume you stored student data in the session after inserting in the database.

Then again you have to update your session data after database update operation.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement