i have this form. when user hit sumbit button i want to run changepassword.php

<form action = 'changepassword.php' method = 'POST'>
    Old password: <input type='password' name='old_password'><br/>
    New password: <input type='password' name = 'new_password'><br/>
    Confirm password: <input type='password' name = 'confirm_new_password'><br/>
    <input type='submit'  value='Change password'>
</form>

so when user hit submit i want to run this if statment. for some reason it doesnt go in this if statment.

    if(isset($_POST['submit']))
    { ... }

full code below.---------------------------------------------------------------------------------------------------

<?php
session_start();
include("connect.php");

$user = $_SESSION['username'];

if($user)
{
    //user is logged in
    if(isset($_POST['submit']))
    {
        echo "work dam ist";
        //checkfields
        $old_password = md5($_POST['old_password']);
        $new_password = md5($_POST['new_password']);
        $confirm_new_password = md5($_POST['confirm_new_password']);

        echo $old_password/$new_password/$confirm_new_password;

        $queryget = mysql_query("SELECT password FROM user WHERE username = '$user'") or die("query didnt work");
        $row = mysql_fetch_assoc($queryget);    
        $old_passworddb = $row['password']; //new variable(old_passworddb)

            //check old password
            if($old_password == $old_passworddb)
            {
                //check two new passwords
                if($new_password == $confirm__new_password)
                {
                    //Success
                    //put new password in data base
                    $querychange = mysql_query("
                    UPDATE user SET password = '$new_password' WHERE username = '$user'");
                    session_destroy();
                    die ("Your password has been changed. <a href='index.php'> Return </a> to the main page");
                }
                else
                    die("New password dont match");

            }
            else
                die("Old password dont match");
    }
}
else
{
    die("you must be logged in to change your password!");
}
?>



<form action = 'changepassword.php' method = 'POST'>
    Old password: <input type='password' name='old_password'><br/>
    New password: <input type='password' name = 'new_password'><br/>
    Confirm password: <input type='password' name = 'confirm_new_password'><br/>
    <input type='submit'  value='Change password'>
</form>

<input type='submit' name='submit' value='Change password'>

use var_dump($_POST); to investigate.

iam not familar with "var_dump($_POST);". how do i use it.

Wrong use of if(isset($_POST['submit'])) here, what you're looking for is:

<?php

    if($_SERVER['REQUEST_METHOD'] == 'POST') {

        // Validate and Execute Password Change Code ...

    } else {

        // Display Form

    }

?>

http://php.net/manual/en/reserved.variables.server.php

this is so wired it works. but on my other code it doesnt work.
thanks, smeage13

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.