gpt4 book ai didi

php - 提交时显示PHP错误

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

我试图在用户输入当前密码并且密码正确但不再输入任何内容时弹出错误消息。所以例如用户想要更改他/她的密码,输入当前密码并输入正确的密码,然后按提交。它应该显示一条错误消息“请输入所有字段!”。现在什么都没有,我真的被困住了:(

任何帮助都会很棒!

图片 1:http://gyazo.com/e58f10783bf14c79de487f4eeb05f7e8

图像 2:http://gyazo.com/ea789cc87166cea88453d6c1c59733b6

(这里应该说,请填写所有字段!)

我的代码:

<title>Hondac</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='http://fonts.googleapis.com/css?family=Julius+Sans+One' rel='stylesheet' type='text/css'>
<link href="../css/style.css" rel="stylesheet" type="text/css" media="all" />



<?php
session_start();



$username = $_SESSION['sess_user'];

echo '<div class="search1"><h2>'.$username.'</h2><div class="search12"><h2><a href="index.php">Home</a></h2></p></div></div>';


if (isset($_SESSION['sess_user']))
{
//user is logged in

if (isset($_POST['submit']))
{
//start changing password
//check fields

$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);


$repeatnewpassword = md5($_POST['repeatnewpassword']);


//check password against db
include('../includes/config.php');

$queryget = mysql_query("SELECT password FROM login WHERE username='$username'") or die ("change password failed");
$row = mysql_fetch_assoc($queryget);
$oldpassworddb = $row['password'];

//check passwords
if ($oldpassword==$oldpassworddb && !empty($_POST['oldpassword']))



{



if (isset($_POST['repeatnewpassword']) AND isset($_POST['newpassword']) AND $_POST['newpassword'] != '') {
if ($newpassword==$repeatnewpassword)
{
$querychange = mysql_query("UPDATE login SET password='$newpassword' WHERE username='$username'");
echo "<div class='successmate'><br><br><br><br><hr>Password has been changed!</hr></div><div class='successmate'><br><hr><br><h2><p><a href='index.php'><br><br></a></p></h2></div>";
}
else {echo "<div class='results'>new password(s) dont match</div><div class='successmate'><br><br><h2><p><a href='changepassword.php'>try again?</a></p></h2></div>";}

}




}
else {echo "<div class='results'>current password doesnt match</div><div class='successmate'><h2><p><a href='changepassword.php'><br><br>Try again?</a></p></h2></div>";}





if (isset($_POST['email']) AND $_POST['email'] != '') {
$querychange = mysql_query("UPDATE login SET email='$email' WHERE username='$username'");
echo "<div class='successmate'><br><br><br><br><hr>Your email has been changed</hr></div><div class='successmate'><br><hr><br><h2><p><a href='index.php'><br><br></a></p></h2></div>";
}}


else
{

echo"
<form class='search1' action='changepassword.php' method='POST'>
<label>Current Password:*</label> <input type='password' id='password' name='oldpassword' required><p>
<label>New Password:*</label> <input type='password' id='password' name='newpassword'><p>
<label>Repeat New Password:*</label> <input type='password' name='repeatnewpassword'><p>
<input type='submit' name='submit' class='submit' value='submit'><br><br><br>
</form>
";


}}
else
die ("You must be logged in to change your password");


?>

<img src="../images/main.jpg">

最佳答案

检查字段是否为空:

if(empty($newpassword) || empty($repeatnewpassword)){
echo 'All fields required.';
}else{
//continue with code
}

关于php - 提交时显示PHP错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26725269/

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