注册页面 这是注册页面,工作正常。
<!DOCTYPE html>
<html>
<head>
<title>REGISTER HERE</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="wrapper">
<?php
<?php
require_once("inc/connection.php");
if(isset($_POST['submit'])){
$name = $_POST['name'];
$password= $_POST['password'];
$day = $_POST['dob'];
$month=$_POST['dob2'];
$year = $_POST['dob3'];
if(isset($_POST['gender'])){
$gender = $_POST['gender'];
}
if(isset($_FILES['upload'])){
$filename = $_FILES['upload']['name'];
$filetmp = $_FILES['upload']['tmp_name'];
$filetype = $_FILES['upload']['type'];
$fileError= $_FILES['upload']['error'];
$filesize= $_FILES['upload']['size'];
}
$max=1000000;
if(!empty($name) && !empty($password) && !empty($day) && !empty($month) && !empty($year) && isset($gender)){
if(!empty($password)){
$password=sha1($password);
if(!empty($name)){
$query=mysqli_query($conn,"SELECT * FROM govtup WHERE name='$name'");
$count=mysqli_num_rows($query);
if ($count==1) {
echo "This name is already registered please choose another username";
}else{
if($fileError==0){
if($filesize<=$max){
if (($filetype=="text/plain") || ($filetype=="application/msword")){
move_uploaded_file($filetmp, "document/".rand(100,9999999).time()."$filename");
$query2=mysqli_query($conn,"INSERT INTO govtup(name,password,day,month,year,gender) VALUES ('$name','$password','$day','$month','$year','$gender')");
if($query2){
unset($name);
header("Location: login.php");
echo "Successfully registered";
}else{
echo "not registered";
}
}else{
echo "only txt and doc file allowed";
}
}else{
echo "The file is too big please choose filesize less than 1mb";
}
}else{
echo "please choose a txt or doc file to upload";
}
}
}
}
}else{
echo "Please fill all the field";
}
}
?>
?>
<form enctype="multipart/form-data" method="post" action="" id="form">
<label class="lb">USERNAME</label><p>
<input type="text" name="name" class="int" placeholder="Please Enter Your Name" value="<?php echo isset($name)?$name:"" ?>" /><p>
<label class="lb">PASSWORD</label><p>
<input type="password" name="password" class="int" placeholder="Please Enter Your Password"/><p>
<label class="lb">D.O.B</label><p>
<select name="dob">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select name="dob2">
<option value="jan">jan</option>
<option value="feb">feb</option>
<option value="mar">mar</option>
<option value="april">april</option>
</select>
<select name="dob3">
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1994">1995</option>
</select>
<P>
<label class="lb">MALE</label>
<input type="radio" name="gender" value="male" />
<label class="lb">FEMALE</label>
<input type="radio" name="gender" value="female"/>
<p>
<label class="lb">UPLOAD FILE</label>
<!-- <input type="hidden" name="MAX_FILE_SIZE" value="1000000"/> -->
<input type="file" class="int" name="upload" /><p>
<input type="submit" name="submit" value="Register Me"> <a href="login.php" style="font-size:20px;">Login Here..</a>
</form>
</div>
</body>
</html>
登录页面 这是login.php它工作正常,直到我只是注册并注销然后登录,但当我登录并编辑我的edit.php页面中的详细信息,然后退出后注销我无法再次登录说&#39;电子邮件或密码组合错误&#39;当名称和密码不匹配时,这是一条消息。
?>
<!DOCTYPE html>
<html>
<head>
<title>REGISTER HERE</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="wrapper">
<?php
require_once("inc/connection.php");
if(isset($_POST['submit'])){
$name = mysqli_real_escape_string($conn,$_POST['name']);
$password = mysqli_real_escape_string($conn,sha1($_POST['password']));
if(!empty($name) && !empty($password)){
$query=mysqli_query($conn,"SELECT * FROM govtup WHERE name='$name' and password='$password'");
$count=mysqli_num_rows($query);
if($count==1){
$data=mysqli_fetch_assoc($query);
unset($data['password']);
if(isset($_POST['keep'])){
setcookie("usercookie",$data['name'],time()+(60));
}
$_SESSION['usersession']=$data;
header("Location: index.php");
$_SESSION['msg']="You have been successfully logedin!";
}else{
echo "Your name and password combination is wrong";
}
}else{
echo "Please Enter your login name and password";
}
}
?>
<form method="post" action="" id="form">
<p>
<label class="lb">USERNAME</label><p>
<input type="text" name="name" class="int" placeholder="Please Enter Your Name" value="<?php echo isset($name)?$name:"" ?>" /><p>
<label class="lb">PASSWORD</label><p>
<input type="password" name="password" class="int" placeholder="Please Enter Your Password"/><p>
Remember me:<input type="checkbox" name="keep"/>
<input type="submit" name="submit" value="log in"> <a href="register.php" style="font-size:20px;">Register Here..</a><p>
</form>
</div>
</body>
</html>
Edit.php页面 这是创建问题的edit.php页面所以请帮我解决这个问题问题是每当我编辑此页面中的任何用户详细信息然后注销并尝试再次登录它不允许我登录再次说&#39;电子邮件和密码组合错误&#34;(这是echo msg)。我试图从早上解决这个问题,但没有找到问题所在。
<?php
session_start();
require_once("inc/connection.php");
if(empty($_SESSION['usersession']))
{
header("Location: login.php");
}
if(isset($_SESSION['msg']))
{
echo $_SESSION['msg'];
unset($_SESSION['msg']);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>REGISTER HERE</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="wrapper">
<?php
require_once("inc/connection.php");
if(isset($_POST['update']))
{
$name = mysqli_real_escape_string($conn,$_POST['name']);
$password= mysqli_real_escape_string($conn,sha1($_POST['password']));
$day = mysqli_real_escape_string($conn,$_POST['dob']);
$month=mysqli_real_escape_string($conn,$_POST['dob2']);
$year = mysqli_real_escape_string($conn,$_POST['dob3']);
$gender = mysqli_real_escape_string($conn,$_POST['gender']);
$id=$_SESSION['usersession']['id'];
if(isset($_POST['gender']))
{
$gender = mysqli_real_escape_string($conn,$_POST['gender']);
}
if(isset($_FILES['upload']))
{
$filename = $_FILES['upload']['name'];
$filetmp = $_FILES['upload']['tmp_name'];
$filetype = $_FILES['upload']['type'];
$fileError= $_FILES['upload']['error'];
$filesize= $_FILES['upload']['size'];
}
$max=1000000;
if(!empty($name && $password && $day && $month && $year))
{
if(!empty($password))
{
$password=sha1($password);
if(!empty($name))
{
$query=mysqli_query($conn,"SELECT * FROM govtup WHERE name='$name'");
$count=mysqli_num_rows($query);
if($count==1)
{
echo "This username is already registered please choose another one";
}
else
{
if($fileError==0)
{
if($filesize<=$max)
{
if($filetype="text/plain" || $filetype="application/msword")
{
move_uploaded_file($filetmp, "document/".rand(100,9999999).time()."$filename");
$query2=mysqli_query($conn,"UPDATE govtup SET name='$name',password='$password',day='$day',month='$month',year='$year',gender='$gender' WHERE id='$id'");
if($query2)
{
header("Location: index.php");
}
else
{
echo "Not Updated";
}
$_SESSION['msg']="You detail Updated";
$_SESSION['usersession']['name']=$name;
}
}
}
}
}
}
}
}
?>
<form enctype="multipart/form-data" method="post" action="" id="form">
<label class="lb">USERNAME</label><p>
<input type="text" name="name" class="int" placeholder="Please Enter Your Name" value="<?php echo $_SESSION['usersession']['name']; ?>" /><p>
<label class="lb">PASSWORD</label><p>
<input type="password" name="password" class="int" placeholder="Please Enter Your Password"/><p>
<label class="lb">D.O.B</label><p>
<select name="dob">
<option><?php echo $_SESSION['usersession']['dob']; ?></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select name="dob2">
<option><?php echo $_SESSION['usersession']['dob2']; ?></option>
<option value="jan">jan</option>
<option value="feb">feb</option>
<option value="mar">mar</option>
<option value="april">april</option>
</select>
<select name="dob3">
<option><?php echo $_SESSION['usersession']['dob3']; ?></option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1994">1995</option>
</select>
your current dob:<?php echo $_SESSION['usersession']['day']."-".$_SESSION['usersession']['month']."-".$_SESSION['usersession']['year']; ?><p>
<P>
<label class="lb">MALE</label>
<input type="radio" name="gender" value="male" />
<label class="lb">FEMALE</label>
<input type="radio" name="gender" value="female"/>
<p>
<label class="lb">UPLOAD FILE</label>
<!-- <input type="hidden" name="MAX_FILE_SIZE" value="1000000"/> -->
<input type="file" class="int" name="upload"/><p>
<input type="submit" name="update" value="Update">
</form>
</div>
</body>
</html>
答案 0 :(得分:0)
将$password=mysqli_real_escape_string($conn,sha1($_POST['password']));
替换为$password= mysqli_real_escape_string($conn,$_POST['password']);
中的edit.php
。
您正在SHA1
中应用edit.php
两次。所以它在插入数据库之前加密密码两次。当您登录时,您只加密一次,因此密码不匹配,因此您会收到错误。
对于第二个问题,请使用以下代码替换<option>
的代码:
<select name="dob">
<? php
$i;
for($i = 1; $i < 31; $i++)
{
if($i == $_SESSION['usersession']['dob'];)
echo '<option selected="selected" value = "'.$i.'">'.$i.'</option>'
else
echo '<option value = "'.$i.'">'.$i.'</option>'
}
?>
</select>