我有一个用户个人资料页面,可以提取已登录的用户信息。正如您所看到的,我已经使用提交按钮设置了更改后的信息被发送到edit_profile.php我已检查它是否带有回声。一切都到了,除了密码,我不知道为什么。
我的问题是如何获取更新SQL的新更新细节。
以下是我的个人资料页面。
<!-- loads the php file into here -->
<?php
/* This script pulls the existing name input and displays it when the user logs in. */
session_start();
include("connection.php");
$query="SELECT * FROM users WHERE id='".$_SESSION['id']."' LIMIT 1";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>MyBday</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Lato:400,300,100,300italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="resources/css/profilestyles.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body data-spy="scroll" data-target=".navbar-collapse">
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">MyBday</a>
</div>
<div class="collapse navbar-collapse">
<form class="navbar-form navbar-right" method="post">
<ul class="nav nav-pills">
<li role="presentation"><a href="mainpage.php">My connections</a></li>
<li role="presentation"><a href="#">World connections</a></li>
<li role="presentation" class="active"><a href="profile.php">Profile</a></li>
<li role="presentation"><a href="#">Messages</a></li>
<li role="presentation"><a href="index.php?logout=1">Logout</a></li>
</ul>
</form>
</div>
</div>
</div>
<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">
<h6>Upload a different photo...</h6>
<input class="form-control" type="file">
</div>
</div>
<!-- edit form column -->
<div class="col-md-9 personal-info">
<div class="alert alert-info alert-dismissable">
<a class="panel-close close" data-dismiss="alert">×</a>
<i class="fa fa-coffee"></i>
This is an <strong>.alert</strong>. Use this to show important messages to the user.
</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">
</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">
</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">
</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">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Password:</label>
<div class="col-md-8">
<input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Confirm password:</label>
<div class="col-md-8">
<input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
</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" 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>
</body>
</html>
当按下提交按钮时,它会转到edit_profile.php,这就是目前的情况。
<?php
session_start();
include("connection.php");
$query="SELECT * FROM users WHERE id='".$_SESSION['id']."' LIMIT 1";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
$name= $_POST['name']; echo $name;
$email= $_POST['email']; echo $email;
$DOB= $_POST['DOB']; echo $DOB;
$country= $_POST['country']; echo $country;
$password= $_POST['password']; echo $password;
?>
我在这里缺少什么脚本来更新数据库。我如何确保不将用户引导到空白的edit_profile.php页面
非常感谢任何帮助。
答案 0 :(得分:1)
关于密码,请看:
<div class="form-group">
<label class="col-md-3 control-label">Password:</label>
<div class="col-md-8">
<input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Confirm password:</label>
<div class="col-md-8">
<input class="form-control" value="<?php echo $row['pasword'];?>" placeholder="At least 8 characters and 1 cap letter" type="password" name="password">
</div>
</div>
您是否看到输入错误:
$row['pasword']
我认为你有问题,然后使用:
$password= $_POST['password']; echo $password;
然后,您需要构建更新查询,例如:
$query = "UPDATE users column_name='".$name."', ' ... WHERE id='".$_SESSION['id']."'";
并执行它:
$result = mysqli_query($link,$query);
使用check检查更新是否成功,这是非常基本的:
http://www.w3schools.com/php/php_mysql_update.asp
此致