• 05-07-2023, 00:35:05
    #1
    Merhaba arkadaşlar

    php kodunun içeriğini resimde görünen tabloya göre düzenleyecek yardımcı olabilecek biri var mı ?

    <?php
    session_start();
    $_SESSION["userId"] = "1";
    $conn = mysqli_connect("localhost", "root", "", "password_change");
    if (count($_POST) > 0) {
    
        $sql = "SELECT * FROM users WHERE userId= ?";
        $statement = $conn->prepare($sql);
        $statement->bind_param('i', $_SESSION["userId"]);
        $statement->execute();
        $result = $statement->get_result();
        $row = $result->fetch_assoc();
    
        if (! empty($row)) {
            $hashedPassword = $row["password"];
            $password = PASSWORD_HASH($_POST["newPassword"], PASSWORD_DEFAULT);
            if (password_verify($_POST["currentPassword"], $hashedPassword)) {
                $sql = "UPDATE users set password=? WHERE userId=?";
                $statement = $conn->prepare($sql);
                $statement->bind_param('si', $password, $_SESSION["userId"]);
                $statement->execute();
                $message = "Password Changed";
            } else
                $message = "Current Password is not correct";
        }
    }
    ?>
    <html>
    <head>
    <title>Change Password</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/form.css" />
    <script>
    function validatePassword() {
        var currentPassword, newPassword, confirmPassword, output = true;
    
        currentPassword = document.frmChange.currentPassword;
        newPassword = document.frmChange.newPassword;
        confirmPassword = document.frmChange.confirmPassword;
    
        if (!currentPassword.value) {
            currentPassword.focus();
            document.getElementById("currentPassword").innerHTML = "required";
            output = false;
        }
        else if (!newPassword.value) {
            newPassword.focus();
            document.getElementById("newPassword").innerHTML = "required";
            output = false;
        }
        else if (!confirmPassword.value) {
            confirmPassword.focus();
            document.getElementById("confirmPassword").innerHTML = "required";
            output = false;
        }
        if (newPassword.value != confirmPassword.value) {
            newPassword.value = "";
            confirmPassword.value = "";
            newPassword.focus();
            document.getElementById("confirmPassword").innerHTML = "not same";
            output = false;
        }
        return output;
    }
    </script>
    </head>
    <body>
        <div class="phppot-container tile-container">
            <form name="frmChange" method="post" action=""
                onSubmit="return validatePassword()">
    
                <div class="validation-message text-center"><?php if(isset($message)) { echo $message; } ?></div>
                <h2 class="text-center">Change Password</h2>
                <div>
                    <div class="row">
                        <label class="inline-block">Current Password</label> <span
                            id="currentPassword" class="validation-message"></span> <input
                            type="password" name="currentPassword" class="full-width">
    
                    </div>
                    <div class="row">
                        <label class="inline-block">New Password</label> <span
                            id="newPassword" class="validation-message"></span><input
                            type="password" name="newPassword" class="full-width">
    
                    </div>
                    <div class="row">
                        <label class="inline-block">Confirm Password</label> <span
                            id="confirmPassword" class="validation-message"></span><input
                            type="password" name="confirmPassword" class="full-width">
    
                    </div>
                    <div class="row">
                        <input type="submit" name="submit" value="Submit"
                            class="full-width">
                    </div>
                </div>
    
            </form>
        </div>
    </body>
    </html>
  • 05-07-2023, 00:36:16
    #2
    www.sabamedya.com
    Yaz hocam
  • 05-07-2023, 09:01:39
    #3
    güncel yardımcı olabilecek biri var mı ?
  • 05-07-2023, 11:45:55
    #4
    fatty adlı üyeden alıntı: mesajı görüntüle
    güncel yardımcı olabilecek biri var mı ?
    Bu şekilde dener misin
    <?php
    session_start();
    $_SESSION["userId"] = "1";
    $conn = mysqli_connect("localhost", "root", "", "password_change");
    if (count($_POST) > 0) {
     
        $sql = "SELECT * FROM yonetici WHERE id= ?";
        $statement = $conn->prepare($sql);
        $statement->bind_param('i', $_SESSION["userId"]);
        $statement->execute();
        $result = $statement->get_result();
        $row = $result->fetch_assoc();
     
        if (! empty($row)) {
            $hashedPassword = $row["password"];
            $password = PASSWORD_HASH($_POST["newPassword"], PASSWORD_DEFAULT);
            if (password_verify($_POST["currentPassword"], $hashedPassword)) {
                $sql = "UPDATE yonetici set sifresi=? WHERE id=?";
                $statement = $conn->prepare($sql);
                $statement->bind_param('si', $password, $_SESSION["userId"]);
                $statement->execute();
                $message = "Password Changed";
            } else
                $message = "Current Password is not correct";
        }
    }
    ?>
    <html>
    <head>
    <title>Change Password</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/form.css" />
    <script>
    function validatePassword() {
        var currentPassword, newPassword, confirmPassword, output = true;
     
        currentPassword = document.frmChange.currentPassword;
        newPassword = document.frmChange.newPassword;
        confirmPassword = document.frmChange.confirmPassword;
     
        if (!currentPassword.value) {
            currentPassword.focus();
            document.getElementById("currentPassword").innerHTML = "required";
            output = false;
        }
        else if (!newPassword.value) {
            newPassword.focus();
            document.getElementById("newPassword").innerHTML = "required";
            output = false;
        }
        else if (!confirmPassword.value) {
            confirmPassword.focus();
            document.getElementById("confirmPassword").innerHTML = "required";
            output = false;
        }
        if (newPassword.value != confirmPassword.value) {
            newPassword.value = "";
            confirmPassword.value = "";
            newPassword.focus();
            document.getElementById("confirmPassword").innerHTML = "not same";
            output = false;
        }
        return output;
    }
    </script>
    </head>
    <body>
        <div class="phppot-container tile-container">
            <form name="frmChange" method="post" action=""
                onSubmit="return validatePassword()">
     
                <div class="validation-message text-center"><?php if(isset($message)) { echo $message; } ?></div>
                <h2 class="text-center">Change Password</h2>
                <div>
                    <div class="row">
                        <label class="inline-block">Current Password</label> <span
                            id="currentPassword" class="validation-message"></span> <input
                            type="password" name="currentPassword" class="full-width">
     
                    </div>
                    <div class="row">
                        <label class="inline-block">New Password</label> <span
                            id="newPassword" class="validation-message"></span><input
                            type="password" name="newPassword" class="full-width">
     
                    </div>
                    <div class="row">
                        <label class="inline-block">Confirm Password</label> <span
                            id="confirmPassword" class="validation-message"></span><input
                            type="password" name="confirmPassword" class="full-width">
     
                    </div>
                    <div class="row">
                        <input type="submit" name="submit" value="Submit"
                            class="full-width">
                    </div>
                </div>
     
            </form>
        </div>
    </body>
    </html>