我的php中有问题,因为用户更新的数据未显示在页面中,它仅显示以前的数据,而不显示更新的数据,而是数据库中已更新的信息
这是我的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:   </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>
这是我的stdUpdateData.php,sql数据库在其中处理更新数据:
<?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);
?>
这是studentProfile.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">
<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>
答案 0 :(得分:1)
我假设您在将学生数据插入数据库后将其存储在会话中。
然后再次需要在数据库更新操作后更新会话数据。