我的帐户上的语法错误\u settings.php
我正在学习一个在线教程。问题是我越来越 语法错误在最后一个ELSE的第二个上出现意外的T_ELSE PHP空白 我曾尝试使用notepad++对PHP空白进行排序,但它不会消失。我目前正在使用PHP8。错误可能来自哪里 这是我的帐户设置.php页面:我的帐户上的语法错误\u settings.php,php,Php,我正在学习一个在线教程。问题是我越来越 语法错误在最后一个ELSE的第二个上出现意外的T_ELSE PHP空白 我曾尝试使用notepad++对PHP空白进行排序,但它不会消失。我目前正在使用PHP8。错误可能来自哪里 这是我的帐户设置.php页面: <?php include( "header inc.php" ); if (!$user) { } else { die ("You must be logged in to view this page!"); } ?> &l
<?php
include( "header inc.php" );
if (!$user) {
}
else
{
die ("You must be logged in to view this page!");
}
?>
<?php
$senddata = @$_POST['senddata'];
//Password variables
$old_password = mysqli_real_escape_string($mysqli,@$_POST['oldpassword']);
$new_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword']);
$repeat_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword2']);
if ($senddata)
//If the form is submitted..
$password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
while ($row = mysqli_fetch_assoc($password_query)) {
$db_password = $row['password'];
//md5 the old password before we check if it matches
$old_password_md5 = md5($old_password);
//Check whether old password equals $db_password
if ($old_password_md5 == $db_password) {
//Continue Changing the users password ...
//Check whether the 2 new passwords match
if ($new_password == $repeat_password) {
//md5 the new password before we add it to the database
$new_password_md5 = md5($new_password);
//Great! Update the users passwords!
$password_update_query = $mysqli->query("UPDATE users SET password='$new_password_md5' WHERE username='$user'");
echo "Success! Your password has been updated!";
}
}
else
{
echo "Your two new passwords don't match!";
}
}
else
{
echo "The old password is incorrect!";
}
}
else
{
echo "";
}
?>
<h2>Edit your Account Settings below</h2>
<hr />
<form action="account_settings.php" accept-charset="utf-8" method="post">
<p>CHANGE YOUR PASSWORD:</p> <br />
Your Old Password: <input type="text" name="oldpassword" id="oldpassword" size="40"><br />
Your New Password: <input type="text" name="newpassword" id="newpassword" size="40"><br />
Repeat Password : <input type="text" name="newpassword2" id="newpassword2" size="40"><br />
<hr />
<p>UPDATE YOUR PROFILE INFO:</p> <br />
First Name: <input type="text" name="fname" id="fname" size="40" value="<? echo $db_first_name; ?>"><br />
Last Name: <input type="text" name="lname" id="lname" size="40" value="<? echo $db_last_name; ?>"><br />
About You: <textarea name="about you" id="about you" rows="7" cols="40"></textarea>
<hr />
<input type="submit" name="senddata" id="senddata" value="Update Information">
</form>
语法错误出现在else
条件中
试一试
最后,下面提到的else没有IF
}
else
{
echo "";
}
修正了,试试这个:
<?php
include( "header inc.php" );
if (!$user) {
}
else
{
die ("You must be logged in to view this page!");
}
?>
<?php
$senddata = @$_POST['senddata'];
//Password variables
$old_password = mysqli_real_escape_string($mysqli,@$_POST['oldpassword']);
$new_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword']);
$repeat_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword2']);
if ($senddata) {
//If the form is submitted..
$password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
while ($row = mysqli_fetch_assoc($password_query)) {
$db_password = $row['password'];
//md5 the old password before we check if it matches
$old_password_md5 = md5($old_password);
//Check whether old password equals $db_password
if ($old_password_md5 == $db_password) {
//Continue Changing the users password ...
//Check whether the 2 new passwords match
if ($new_password == $repeat_password) {
//md5 the new password before we add it to the database
$new_password_md5 = md5($new_password);
//Great! Update the users passwords!
$password_update_query = $mysqli->query("UPDATE users SET password='$new_password_md5' WHERE username='$user'");
echo "Success! Your password has been updated!";
}
}
else
{
echo "Your two new passwords don't match!";
}
}
}
else
{
echo "The old password is incorrect!";
}
?>
<h2>Edit your Account Settings below</h2>
<hr />
<form action="account_settings.php" accept-charset="utf-8" method="post">
<p>CHANGE YOUR PASSWORD:</p> <br />
Your Old Password: <input type="text" name="oldpassword" id="oldpassword" size="40"><br />
Your New Password: <input type="text" name="newpassword" id="newpassword" size="40"><br />
Repeat Password : <input type="text" name="newpassword2" id="newpassword2" size="40"><br />
<hr />
<p>UPDATE YOUR PROFILE INFO:</p> <br />
First Name: <input type="text" name="fname" id="fname" size="40" value="<? echo $db_first_name; ?>"><br />
Last Name: <input type="text" name="lname" id="lname" size="40" value="<? echo $db_last_name; ?>"><br />
About You: <textarea name="about you" id="about you" rows="7" cols="40"></textarea>
<hr />
<input type="submit" name="senddata" id="senddata" value="Update Information">
</form>
请正确缩进您的代码以便更容易理解。我目前正在使用PHP8,那个么怎么样?为什么会有反对票?哦,上帝,他使用md5散列他的密码。。。请迁移到新的PHP5.5密码哈希API(甚至还有5.3和5.4的库)。@Antony您的代码存在一些严重的缩进问题。当然,这并不是问题的根源,但是,它让阅读变得困难。想想看。@Antony如果你觉得我的答案有用,请接受。谢谢Hassaan,bt。新的问题是,当我尝试更改表单上的密码时,没有发生任何情况,如果我使用你编辑的答案,错误会回来。我使用你的第一个答案。它不存在,所以我坚持使用1st@Antony现在请用我的新答案。我有,该错误已消失,但表单不起作用。当我更改密码并按enter/update info时,它只需重新加载即可帮助我解决当前遇到的新问题?该页面不起作用
}
else
{
echo "";
}
<?php
include( "header inc.php" );
if (!$user) {
}
else
{
die ("You must be logged in to view this page!");
}
?>
<?php
$senddata = @$_POST['senddata'];
//Password variables
$old_password = mysqli_real_escape_string($mysqli,@$_POST['oldpassword']);
$new_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword']);
$repeat_password = mysqli_real_escape_string($mysqli,@$_POST['newpassword2']);
if ($senddata) {
//If the form is submitted..
$password_query = $mysqli->query("SELECT * FROM users WHERE username='$user'");
while ($row = mysqli_fetch_assoc($password_query)) {
$db_password = $row['password'];
//md5 the old password before we check if it matches
$old_password_md5 = md5($old_password);
//Check whether old password equals $db_password
if ($old_password_md5 == $db_password) {
//Continue Changing the users password ...
//Check whether the 2 new passwords match
if ($new_password == $repeat_password) {
//md5 the new password before we add it to the database
$new_password_md5 = md5($new_password);
//Great! Update the users passwords!
$password_update_query = $mysqli->query("UPDATE users SET password='$new_password_md5' WHERE username='$user'");
echo "Success! Your password has been updated!";
}
}
else
{
echo "Your two new passwords don't match!";
}
}
}
else
{
echo "The old password is incorrect!";
}
?>
<h2>Edit your Account Settings below</h2>
<hr />
<form action="account_settings.php" accept-charset="utf-8" method="post">
<p>CHANGE YOUR PASSWORD:</p> <br />
Your Old Password: <input type="text" name="oldpassword" id="oldpassword" size="40"><br />
Your New Password: <input type="text" name="newpassword" id="newpassword" size="40"><br />
Repeat Password : <input type="text" name="newpassword2" id="newpassword2" size="40"><br />
<hr />
<p>UPDATE YOUR PROFILE INFO:</p> <br />
First Name: <input type="text" name="fname" id="fname" size="40" value="<? echo $db_first_name; ?>"><br />
Last Name: <input type="text" name="lname" id="lname" size="40" value="<? echo $db_last_name; ?>"><br />
About You: <textarea name="about you" id="about you" rows="7" cols="40"></textarea>
<hr />
<input type="submit" name="senddata" id="senddata" value="Update Information">
</form>