gpt4 book ai didi

php - 个人资料页面不显示用户个人资料信息或更新

转载 作者:行者123 更新时间:2023-11-29 11:37:13 25 4
gpt4 key购买 nike

希望有人能帮忙。我有一个个人资料页面,我想显示登录用户的详细信息。到目前为止,我在个人资料页面上有这个。

<?php  

/* This script pulls the existing name input and displays it when the user logs in. */

session_start();

include("db.php"); ?>

<?php include("includes/header.php") ?>

<?php include("includes/nav.php") ?>




<?php

if(logged_in()) {

$result = mysqli_query($link,$query);

$row = mysqli_fetch_array($result);


if (!$_POST['name'] && $_POST['name']=="") $error.="<br />Please enter your name";
if (!$_POST['email'] && $_POST['email']=="") $error.="<br />Please enter your email";
if (!$_POST['DOB'] && $_POST['DOB']=="") $error.="<br />Please enter your date of birth";
if (!$_POST['country'] && $_POST['country']=="") $error.="<br />Please enter your country";




if ($error) {

echo '<div class="alert alert-success alert-dismissable">'.addslashes($error).'</div>';

}

if(isset($_POST['form-control'])) {

move_uploaded_file($_FILES['file']['tmp_name'],"img/".$_FILES['file']['name']);
$query = mysqli_query("UPDATE users SET image = '".$_FILES['file']['name']."'");
}


} else {

redirect("login.php");

}

?>


<Style>


.alert{
display:none;
}

#profileimg {
height: 100px;
width: auto;
}

</Style>


<div class="container">
<h1>Edit Profile</h1>
<hr>
<div class="row">
<!-- left column -->
<div class="col-md-3">
<div class="text-center">
<img src="//placehold.it/100" class="avatar img-circle" alt="avatar" id="profileimg">
<h6>Upload a different photo...</h6>

<input class="form-control" type="file" name="name">
</div>
</div>

<!-- edit form column -->
<div class="col-md-9 personal-info">
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
<strong>Profile updated.</strong>
</div>
<h3>Personal info</h3>

<form class="form-horizontal" role="form" action="edit_profile.php" method="post">

<div class="form-group">
<label class="col-lg-3 control-label name">name:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['name'];?>" type="text" name="name" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['email'];?>" type="text" name="email" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">DOB:</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['DOB'];?>" type="date" name="DOB" required>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Country</label>
<div class="col-lg-8">
<input class="form-control" value="<?php echo $row['country'];?>" type="text" name="country" required>
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="btn btn-primary" value="Save Changes" type="submit">
<span></span>
<input class="btn btn-default" id="updated" value="Cancel" type="reset">
</div>
</div>

</form>
</div>

     <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>

<script>

$("#updated").click(function(){

$(".alert").hide().show('medium');

</script>


</body>
</html>

然后我有另一个用于更新的 php 文件,如下:

<?php

session_start();

include("db.php");



$name = $_POST['name'];
$email = $_POST['email'];
$DOB = $_POST['DOB'];
$country = $_POST['country'];
$password = md5($salt.$_POST['password']);



$query = "UPDATE users SET name = '".$name."', email = '".$email."', DOB = '".$DOB."', country = '".$country."', password = '".$password."'";




$result = mysqli_query($link,$query);




header('Location: profile.php');

?>

所以缺点是它不显示或更新,我不知道为什么。我是 PHP 新手,所以如果这很简单,请放轻松,我已经搜索过,但似乎找不到答案。

提前致谢。

最佳答案

我对此也很陌生,但通常当我检查 SESSION id 是否处于事件状态时,我会使用

if(isset($_SESSION['id'])) {
$query = "UPDATE users SET name = '".$name."', email = '".$email."', DOB = '".$DOB."', country = '".$country."', password = '".$password."' WHERE id='".$_SESSION['id']."'";
}

您还需要回显您尝试查询的索引行以显示结果

$name = row['username'];
echo $name;

关于php - 个人资料页面不显示用户个人资料信息或更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36378039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com