Undefined index: Submit

Asked

Viewed 257 times

0

I have the following code and the following error appears to me inserir a descrição da imagem aqui

<?php
$user=$_SESSION['MM_Username'];
if($user){
    //user is logged in
    if($_POST['submit']){
        //start changing password
        $oldpassword=md5($_POST['senha_atual']);
        $newpassword=md5 ($_POST['senha_nova']);
        $repeatnewpassword=md5 ($_POST['confirme_senha']);          
        //check password against db
        //connect db
        mysql_select_db($database_bvmarco, $bvmarco);
        $query_password = sprintf("SELECT password FROM login WHERE numMec = '$user'");
        $password = mysql_query($query_password, $bvmarco) or die(mysql_error());
        $row_password = mysql_fetch_assoc($password);
        $totalRows_password = mysql_num_rows($password);

        $oldpassworddb=$row_password['password'];
        //check password

        if($oldpassword==$oldpassworddb){
            //chek new passwords
            if($newpassword==$repeatnewpassword){
                //success
                //change password in db
                $querychange = mysql_query("UPDATE login SET password='$newpassword' WHERE numMec = '$user'");
                session_destroy();
                die("Password alterada com sucesso!");
            }else{
                die("As password's não são iguais");
            }
        }else{
            die("A password atual não bate certo");
        }
    }else{
        echo"<div class='card-body'>
            <form METHOD='POST' name='password'>
                <div class='align-items-center justify-content-center'>
                  <div class='form-group'>
                        <label><b>Antiga password</b></label>
                        <input type='text' placeholder='Antiga password' name='senha_atual' class='form-control'>
                    </div>
                    <div class='form-group'>
                        <label for='tipo'><b>Nova password</b></label>
                        <input type='text' placeholder='Nova password' name='senha_nova' class='form-control''>
                        <label for='tipo'><b>Confirme password</b></label>
                        <input type='text' placeholder='Nova password' name='confirme_senha' class='form-control'>
                    </div>
                    <input type='submit' name='submit' id='submt' value='Change password'>
                </div>
            </form> 
        </div>";
    }
}else{
    die("Precisas fazer o login para mudar a password!");
}
?>

1 answer

1


That’s not really a mistake, it’s a Notice only, in production this should not even be displayed, read more on:

Still the ideal is to use isset or !empty to check if the variables exist, for example:

<?php
if(!empty($_SESSION['MM_Username'])){
    $user=$_SESSION['MM_Username'];

    //user is logged in
    if(isset($_POST['submit'])){
        //start changing password
        $oldpassword=md5($_POST['senha_atual']);
        $newpassword=md5 ($_POST['senha_nova']);
        $repeatnewpassword=md5 ($_POST['confirme_senha']);          
        //check password against db
        //connect db
        mysql_select_db($database_bvmarco, $bvmarco);
        $query_password = sprintf("SELECT password FROM login WHERE numMec = '$user'");
        $password = mysql_query($query_password, $bvmarco) or die(mysql_error());
        $row_password = mysql_fetch_assoc($password);
        $totalRows_password = mysql_num_rows($password);

        $oldpassworddb=$row_password['password'];
        //check password

        if($oldpassword==$oldpassworddb){
            //chek new passwords
            if($newpassword==$repeatnewpassword){
                //success
                //change password in db
                $querychange = mysql_query("UPDATE login SET password='$newpassword' WHERE numMec = '$user'");
                session_destroy();
                die("Password alterada com sucesso!");
            }else{
                die("As password's não são iguais");
            }
        }else{
            die("A password atual não bate certo");
        }
    }else{
        echo"<div class='card-body'>
            <form METHOD='POST' name='password'>
                <div class='align-items-center justify-content-center'>
                  <div class='form-group'>
                        <label><b>Antiga password</b></label>
                        <input type='text' placeholder='Antiga password' name='senha_atual' class='form-control'>
                    </div>
                    <div class='form-group'>
                        <label for='tipo'><b>Nova password</b></label>
                        <input type='text' placeholder='Nova password' name='senha_nova' class='form-control''>
                        <label for='tipo'><b>Confirme password</b></label>
                        <input type='text' placeholder='Nova password' name='confirme_senha' class='form-control'>
                    </div>
                    <input type='submit' name='submit' id='submt' value='Change password'>
                </div>
            </form> 
        </div>";
    }
}else{
    die("Precisas fazer o login para mudar a password!");
}
?>

Very important: Old mysql API for PHP has been discontinued

All functions starting with mysql_ are part of the old PHP API, it is recommended to switch to one of the new Apis:

  • PDO
  • MYSQLI

Read more on: Mysqli vs PDO - which is the most recommended to use?

  • He’s still giving the same news

  • Notice: Undefined index: Submit in D: wamp64 www bvmarco password.php on line 201

  • if(isset($_POST['Ubmit'])){

  • I before testing on the page write always and I already cleaned the browser cache but it appears in the same

  • How can I do then not to get the news

  • I just changed the code, and I recorded it again and it keeps coming up, I’ll add the code to the top and new image,

  • 1

    I hadn’t noticed, sorry and thanks for your help

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.