我已经创建了一个更改密码的代码。现在它似乎包含一个错误。在我填写表格之前。 页面显示错误消息:
解析错误:解析错误,意外 $结束于C:\ Program 文件\ XAMPP \ htdocs中\电子投诉(FYP)\ userChangePass.php 在第222行
这个代码:
<?php # userChangePass.php
//this page allows logged in user to change their password.
$page_title='Change Your Password';
//if no first_name variable exists, redirect the user
if(!isset($_SESSION['nameuser'])){
header("Location: http://" .$_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF'])."/index.php");
ob_end_clean();
exit();
}else{
if(isset($_POST['submit'])) {//handle form.
require_once('connectioncomplaint.php'); //connec to the database
//check for a new password and match againts the confirmed password.
if(eregi ("^[[:alnum:]]{4,20}$", stripslashes(trim($_POST['password1'])))){
if($_POST['password1'] == $_POST['password2']){
$p =escape_data($_POST['password1']);
}else{
$p=FALSE;
echo'<p><font color="red" size="+1"> Your password did not match the confirmed password!</font></p>';
}
}else{
$p=FALSE;
echo'<p><font color="red" size="+1"> Please Enter a valid password!</font></p>';
}
if($p){ //if everything OK.
//make the query
$query="UPDATE access SET password=PASSWORD('$p') WHERE userid={$_SESSION['userid']}";
$result=@mysql_query($query);//run the query.
if(mysql_affected_rows() == 1) {//if it run ok.
//send an email,if desired.
echo '<p><b>your password has been changed.</b></p>';
//include('templates/footer.inc');//include the HTML footer.
exit();
}else{//if it did not run ok
$message= '<p>Your password could not be change due to a system error.We apolpgize for any inconvenience.</p><p>' .mysql_error() .'</p>';
}
mysql_close();//close the database connection.
}else{//failed the validation test.
echo '<p><font color="red" size="+1"> Please try again.</font></p>';
}
}//end of the main Submit conditional.
?>
表格代码:
<h1>Change Your Password</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<p><b>New Password:</b><input type="password" name="password1" size="20" maxlength="20" />
<small>Use only letters and numbers.Must be between 4 and 20 characters long.</small></p>
<p><b>Confirm New Password:</b><input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>
<div align="center"> <input type="submit" name="submit" value="Change My Password" /></div>
</form><!--End Form-->
答案 0 :(得分:1)
您错过了文件末尾的结束}
。以下语句的else
未关闭:
if(!isset($_SESSION['nameuser'])){
header("Location: http://" .$_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF'])."/index.php");
ob_end_clean();
exit();
}else{
此行}//end of the main Submit conditional.
的最后结束是关闭此行if(isset($_POST['submit'])) {//handle form.
,这将使另一个if
关闭。
答案 1 :(得分:0)
我认为您在}
之前的某个条件中遗漏了?>
。
正确缩进代码会使这些代码更容易被发现。
编辑:
当我暂停时,在第2行到最后一行添加}
,如下所示:
<?php # userChangePass.php
//this page allows logged in user to change their password.
$page_title='Change Your Password';
//if no first_name variable exists, redirect the user
if(!isset($_SESSION['nameuser'])){
header("Location: http://" .$_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF'])."/index.php");
ob_end_clean();
exit();
}else{
if(isset($_POST['submit'])) {//handle form.
require_once('connectioncomplaint.php'); //connec to the database
//check for a new password and match againts the confirmed password.
if(eregi ("^[[:alnum:]]{4,20}$", stripslashes(trim($_POST['password1'])))){
if($_POST['password1'] == $_POST['password2']){
$p =escape_data($_POST['password1']);
}else{
$p=FALSE;
echo'<p><font color="red" size="+1"> Your password did not match the confirmed password!</font></p>';
}
}else{
$p=FALSE;
echo'<p><font color="red" size="+1"> Please Enter a valid password!</font></p>';
}
if($p){ //if everything OK.
//make the query
$query="UPDATE access SET password=PASSWORD('$p') WHERE userid={$_SESSION['userid']}";
$result=@mysql_query($query);//run the query.
if(mysql_affected_rows() == 1) {//if it run ok.
//send an email,if desired.
echo '<p><b>your password has been changed.</b></p>';
//include('templates/footer.inc');//include the HTML footer.
exit();
}else{//if it did not run ok
$message= '<p>Your password could not be change due to a system error.We apolpgize for any inconvenience.</p><p>' .mysql_error() .'</p>';
}
mysql_close();//close the database connection.
}else{//failed the validation test.
echo '<p><font color="red" size="+1"> Please try again.</font></p>';
}
}//end of the main Submit conditional.
}
?>
答案 2 :(得分:0)
当你检查$ _SESSION ['nameuser']时,你错过了关闭你的第一个if / else块。
<?php # userChangePass.php
//this page allows logged in user to change their password.
$page_title='Change Your Password';
//if no first_name variable exists, redirect the user
if(!isset($_SESSION['nameuser'])){
header("Location: http://" .$_SERVER['HTTP_HOST']. dirname($_SERVER['PHP_SELF'])."/index.php");
ob_end_clean();
exit();
}else{
if(isset($_POST['submit'])) {//handle form.
require_once('connectioncomplaint.php'); //connec to the database
//check for a new password and match againts the confirmed password.
if(eregi ("^[[:alnum:]]{4,20}$", stripslashes(trim($_POST['password1'])))){
if($_POST['password1'] == $_POST['password2']){
$p =escape_data($_POST['password1']);
}else{
$p=FALSE;
echo'<p><font color="red" size="+1"> Your password did not match the confirmed password!</font></p>';
}
}else{
$p=FALSE;
echo'<p><font color="red" size="+1"> Please Enter a valid password!</font></p>';
}
if($p){ //if everything OK.
//make the query
$query="UPDATE access SET password=PASSWORD('$p') WHERE userid={$_SESSION['userid']}";
$result=@mysql_query($query);//run the query.
if(mysql_affected_rows() == 1) {//if it run ok.
//send an email,if desired.
echo '<p><b>your password has been changed.</b></p>';
//include('templates/footer.inc');//include the HTML footer.
exit();
}else{//if it did not run ok
$message= '<p>Your password could not be change due to a system error.We apolpgize for any inconvenience.</p><p>' .mysql_error() .'</p>';
}
mysql_close();//close the database connection.
}else{//failed the validation test.
echo '<p><font color="red" size="+1"> Please try again.</font></p>';
}
}//end of the main Submit conditional.
} // end session check
?>