title: Confirm alert displays but when clicking "cancel" it will perfom the delete query anyways
body: <p>i'm currently creating a project which is a website for courses and right now i'm building the profile page of the user with the option of editing and seeing the information of the user, but i have a problem implementing the deleting account functionality.</p>
  <p>There would be a delete button and a pop up for the user when clicking that button. The problem is that even if i click cancel it will perform the query, delete the user and send me to the index page, i don't know if it's a problem with redirecting or that i should echo the script with php instead of calling it from javascript, thanks in advance for any help you could provide.</p>
  <pre><code>&lt;?php 
  
  //selects current data of the logged user and display it
  
  if (isset($_SESSION['id_user'])) {
      $id_session = $_SESSION['id_user'];
  
  
      $query = &quot;SELECT id_user, first_name, last_name, username, email FROM users &quot;;
      $query .= &quot;WHERE id_user = ? &quot;;
  
      $stmt = mysqli_stmt_init($con);
      $prepare = mysqli_stmt_prepare($stmt, $query);
  
      if (!$prepare) {
          die('query failed' . mysqli_error($con));
      } else {
  
          mysqli_stmt_bind_param($stmt, &quot;i&quot;, $id_session);
          mysqli_stmt_execute($stmt);
          $get_user_data = mysqli_stmt_get_result($stmt);
  
          while ($row = mysqli_fetch_assoc($get_user_data)) {
              $id = $row['id_user'];
              $name = $row['first_name'];
              $last_name = $row['last_name'];
              $username = $row['username'];
              $email = $row['email'];
  
  ?&gt;
  
  &lt;div class=&quot;profile-table&quot;&gt;
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;ID&lt;/th&gt;
          &lt;td&gt;&lt;?php echo $id; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;td&gt;&lt;?php echo $name; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;Last name&lt;/th&gt;
          &lt;td&gt;&lt;?php echo $last_name; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;Usernamee&lt;/th&gt;
          &lt;td&gt;&lt;?php echo $username; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th&gt;Email&lt;/th&gt;
          &lt;td&gt;&lt;?php echo $email; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/div&gt;
  
  
  &lt;?php } } } ?&gt;
  
  &lt;div class=&quot;cont-btn&quot;&gt;
  
  &lt;div&gt;
  &lt;a class=&quot;active-btn&quot; href=&quot;profile.php?source=edit&amp;id_u=&lt;?php echo $id; ?&gt;&quot;&gt;Edit profile&lt;/a&gt;   
  &lt;/div&gt;  
  
  &lt;div&gt;   
  &lt;a class=&quot;active-btn del-btn&quot; onClick=&quot;deleteConfirm()&quot; href=&quot;profile.php?delete=&lt;?php echo $id; ?&gt;&quot;&gt;delete account&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  
  
  
  
  &lt;?php 
  
  
  if(isset($_GET['delete'])) {
  
  $id_delete = $_GET['delete'];
  
  $query = &quot;DELETE FROM users WHERE id_user = ? &quot;;
  $stmt = mysqli_stmt_init($conexion);
  $prepare = mysqli_stmt_prepare($stmt, $query);
  
  if(!$prepare) {
      die('Query failed' . mysqli_error($con));
  } else {
      mysqli_stmt_bind_param($stmt, &quot;i&quot;, $id_delete);
      mysqli_stmt_execute($stmt);
      logout();
  
  }
  /* unset everything from session and relocates back to the index page
  
      function logout()
      {
              
      session_start(); 
      unset($_SESSION['id_user']);
      unset($_SESSION['name']);
      unset($_SESSION['lastname']);
      unset($_SESSION['username']);
      unset($_SESSION['email']);
      unset($_SESSION['role']);
      session_destroy();
  
      header(&quot;Location: ../index.php&quot;);
  
      } */
  
  
  
  
  }
  
   ?&gt;
  
   &lt;script&gt;
      function deleteConfirm() {
          confirm('Are you sure you want to delete your account?');
      }
   &lt;/script&gt;
  `
  </code></pre>