login about faq


I'm making a system to change my password and I don't know why I am getting this error. I have this error message: Parse error: syntax error, unexpected T_ELSE in /home/zenonhos/public_html/system/changepass.php on line 37



<?php session_start();

$user = $_SESSION['username'];

if ($user)
{

if ($_POST['submit'])
{
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);

$connect = mysql_connect("*******","******","*****");
mysql_select_db("zenonhos_lr");

$queryget = mysql_query("SELECT `password` FROM `users` WHERE username='$user'") or die();
$row = mysql_fetch_assoc($queryget);
$oldpassworddb = $row['password'];

if ($oldpassword==$oldpassworddb)
{
if ($newpassword == "") {
echo "Password cannot be blank";
} else {

if ($newpassword==$repeatnewpassword)
{
$querychange = mysql_query("UPDATE `users` SET password='$newpassword' WHERE username='$user'");

session_destroy();
die("Password successfully changed! <a href='index.php'>Return to home page</a>");
} else {
die("New passwords do not match");
} else {
die("Old password does not match");
} echo "<form action='changepass.php' method='POST'>
Old Password: <input type='password' name='oldpassword'><br>
New Password: <input type='password' name='newpassword'><br>
Repeat New Password: <input type='password' name='repeatnewpassword'><br>
<input type='submit' name='submit' value='Change Password'>";
} else {
die("You must be logged in to view this page.");
}

?>

asked Jul 07 '12 at 01:52

jonaasmith's gravatar image

jonaasmith
1111


Well I don't know PHP from beef jerky but shouldn't this bracket

} echo (form action='changepass.php' etc.)

not be there?

answered Jul 07 '12 at 08:19

dunfiddlin's gravatar image

dunfiddlin
1.2k418

Format your code a bit nicer and you'll probably see the problem:

<?php session_start();

$user = $_SESSION['username'];

if ($user) {
    if ($_POST['submit']) {
        $oldpassword = md5($_POST['oldpassword']);
        $newpassword = md5($_POST['newpassword']);
        $repeatnewpassword = md5($_POST['repeatnewpassword']);

        $connect = mysql_connect("*******","******","*****");
        mysql_select_db("zenonhos_lr");

        $queryget = mysql_query("SELECT `password` FROM `users` WHERE username='$user'") or die();
        $row = mysql_fetch_assoc($queryget);
        $oldpassworddb = $row['password'];

        if ($oldpassword==$oldpassworddb) {
            if ($newpassword == "") {
                echo "Password cannot be blank";
            } else {
                if ($newpassword==$repeatnewpassword) {
                    $querychange = mysql_query("UPDATE `users` SET password='$newpassword' WHERE username='$user'");

                    session_destroy();
                    die("Password successfully changed! <a href='index.php'>Return to home page</a>");
                } else {
                    die("New passwords do not match");
                } else {
                    die("Old password does not match");
                }
                echo "<form action='changepass.php' method='POST'>" .
                     "Old Password: <input type='password' name='oldpassword'><br>" .
                     "New Password: <input type='password' name='newpassword'><br>" .
                     "Repeat New Password: <input type='password' name='repeatnewpassword'><br>" .
                     "<input type='submit' name='submit' value='Change Password'>";
            } else {
                die("You must be logged in to view this page.");
            }
?>

FYI I cleaned up the last echo statement for clarity, it's not the direct issue.

See what you missed?

answered Jul 07 '12 at 14:08

eddieringle's gravatar image

eddieringle
2.3k71644

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported


Join Us in the Chat Room

Tags:

×974
×95
×63

Asked: Jul 07 '12 at 01:52

Seen: 547 times

Last updated: Jul 07 '12 at 14:08