我有一个提取登录用户详细信息的个人资料页面,我已经停止了密码通过。因为我希望他们重新输入它作为更新细节的一部分。
我想要的是确保它们填写字段,并且无法使用缺少的密码或名称等更新表单。
<!-- 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);
?>
<Style>
.alert{
display:none;
}
</Style>
<!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">
<title>profile</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">
<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-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</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">
</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">Re-enter password:</label>
<div class="col-md-8">
<input class="form-control" value="" 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="" 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" 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>
我有这个脚本,我已从登录中复制但不确定如何将其实现到此个人资料页面。
// check name is valid
if (!$_POST['name']) $error.="<br />Please enter your name";
// check town is valid
// if (!$_POST['town']) $error.="<br />Please enter your town/city.";
// check country is valid
if (!$_POST['country']) $error.="<br />Please enter your country.";
// check DOB is valid
if (!$_POST['DOB']) $error.="<br />Please enter your Date of birth.";
// check email and password exist and are valid
if (!$_POST['email']) $error.="<br />Please enter your email";
// if email exists check it is valid if not display error message
if (!$_POST['email']) $error.="<br />Please enter your email";
else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid email";
// password validation
if (!$_POST['password']) $error.="<br />Please enter your password";
else {
// if they have entered a password check how long it is
if (strlen($_POST['password'])<8) $error.="<br />please enter a password with at least 8 characters";
// check if it doesn't have a cap letter in it
if(!preg_match('/[A-Z]/', $_POST['password'])) $error.= "<br />Please include min 1 capital letter in your password.";
}
if ($error) $error = "There were error(s) in your sign up details:".$error;
我觉得很明显看到php,sql对我来说都是新手,所以尽我所能去理解它,所以要温柔并像我一样解释。
提前致谢。
答案 0 :(得分:1)
您只需在输入字段中添加required
,然后他们就无法提交,直到他们输入您添加required
的所有值,更多关于所需的值:
编辑:
用php检查看起来像这样:
/ check name is valid
if (!$_POST['name'] || $_POST['name']=="") $error.="<br />Please enter your name";
所以只需添加到每个字段|| $_POST['nameofinput']==""
,这是服务器端检查来自html的required