title: PHP ask password before delete
body: <p>I want a web application to ask for the password before deleting. The procedure I created is, before clicking the delete button, a modal will appear and ask for the password for security.</p>
  
  <p>Here is my source code:</p>
  
  <pre><code>&lt;?php
     session_start();
      require 'database.php';
      $id = 0;
  
      if ( !empty($_GET['id'])) {
          $id = $_REQUEST['id'];
      }
  
  
  
  ?&gt;
  
               &lt;?php
  
               if(isset($_POST['login']))
                { 
                  $password = mysql_real_escape_string(trim($_POST["password"], "/\'\"\;"));
                  $msg = '';
  
                  $query = mysql_query("SELECT * from tbl_user where password = '$password'");
                     {
                      while($rwOK = mysql_fetch_assoc($query))
                      {
                        $_SESSION['password'] = $rwOK['password']; 
                      }   
                      if( $_SESSION['password']==$passsowrd)
                      {
                        include 'database.php';
                        $pdo = Database::connect();
                        $sql = 'SELECT * FROM customers ORDER BY id DESC';
                        foreach ($pdo-&gt;query($sql) as $row)
                        {
                        header("Location: delete_member.php?id=$row[id]");
                        }
                      }
                      else if(empty($password))
                      {
                        $msg =  '&lt;i&gt;&lt;font color="red"&gt;Please input Administrator password.&lt;/font&gt;&lt;/i&gt;';
                      }
                      else
                      {
                        //$_SESSION['tae'] = $tae;
                        $msg = '&lt;i&gt;&lt;font color="red"&gt;Invalid Password&lt;/font&gt;&lt;/i&gt;';
                      }
                    }
                  }
  
  
  
                  ?&gt;
  
  
  
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt; Stock Employee &lt;/title&gt;
      &lt;meta charset="utf-8"&gt;
     &lt;link   href="css/bootstrap.min.css" rel="stylesheet"&gt;
      &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt; 
  &lt;/head&gt;
  
  &lt;!-- modal --&gt;
  &lt;!-- 
  &lt;link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt; --&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  &lt;!-- --&gt;
  
  &lt;body&gt;
      &lt;div class="container"&gt;
  
                  &lt;div class="span10 offset1"&gt;
                      &lt;div class="row"&gt;
                          &lt;h3&gt;Delete Record&lt;/h3&gt;
                      &lt;/div&gt;
  
                      &lt;!-- &lt;form class="form-horizontal" action="delete.php" method="post"&gt; --&gt;
                      &lt;form class="form-horizontal" action="&lt;?=$_SERVER['PHP_SELF']?&gt;" method="post"&gt;
                        &lt;input type="hidden" name="id" value="&lt;?php echo $id;?&gt;"/&gt;
                        &lt;p class="alert alert-error"&gt;Are you sure to delete ?&lt;/p&gt;
                        &lt;?php echo !empty($passwordError)?'error':'';?&gt;
                        &lt;div class="form-actions"&gt;
  
                            &lt;!-- &lt;button type="submit" class="btn btn-danger"&gt;Yes&lt;/button&gt; --&gt;
  
                            &lt;!-- Trigger the modal with a button --&gt;
                              &lt;button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal"&gt;Yes&lt;/button&gt;
  
                            &lt;!-- Modal --&gt;
                                &lt;div class="modal fade" id="myModal" role="dialog"&gt;
                                  &lt;div class="modal-dialog"&gt;
  
                                    &lt;!-- Modal content--&gt;
                                    &lt;div class="modal-content"&gt;
                                      &lt;div class="modal-header"&gt;
                                        &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
                                        &lt;h4 class="modal-title"&gt;Administrator Access&lt;/h4&gt;
                                      &lt;/div&gt;
                                      &lt;div class="modal-body"&gt;                                  
  
                                        &lt;div class="control-group &lt;?php echo !empty($passwordError)?'error':'';?&gt;"&gt;
                                          &lt;label class="control-label"&gt;Password :&lt;/label&gt;
                                          &lt;div class="controls"&gt;
                                              &lt;input name="password" type="password"  placeholder="username" required value="&lt;?php echo !empty($password)?$password:'';?&gt;"&gt;
                                              &lt;?php if (!empty($passwordError)): ?&gt;
                                                  &lt;span class="help-inline"&gt;&lt;?php echo $passwordError;?&gt;&lt;/span&gt;
                                              &lt;?php endif; ?&gt;
                                          &lt;/div&gt;
                                        &lt;/div&gt;
  
                                        &lt;div class="control-group"&gt;
                                          &lt;div class="controls"&gt;
                                              &lt;button type="submit" class="btn btn-danger"&gt;Delete&lt;/button&gt;                               
                                          &lt;/div&gt;
                                        &lt;/div&gt;                                     
  
                                      &lt;/div&gt;
                                      &lt;div class="modal-footer"&gt;
                                        &lt;button type="button" class="btn btn-default" data-dismiss="modal" name="login"&gt;Close&lt;/button&gt;
                                      &lt;/div&gt;
                                    &lt;/div&gt;
  
                                  &lt;/div&gt;
                                &lt;/div&gt;
  
                            &lt;a class="btn" href="index.php"&gt;No&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
  
      &lt;/div&gt; &lt;!-- /container --&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any kind of help is much appreciated. Thank you.</p>