简体   繁体   中英

Using if(isset($_POST['submit'])) does not submit

I am trying to make a delete button that open a modal to confirm the delete action (deleting posts) When I click delete inside the modal nothing happens, what is the problem? here is the form code

<form action="" method="post" enctype="multipart/form-data" >
  <input type="submit" name="submit" value="Delete" class="btn btn-default btn-primary" style="color: #580024;" >
  <button type="button" class="btn btn-default" data-dismiss="modal">Close
  </button>
</form>
  <?php
  if(isset($_POST['submit'])) {
  $query = mysqli_query($this->con, "UPDATE posts SET deleted='yes' WHERE id='$id'");
   header('Location: ' . $_SERVER['HTTP_REFERER']);
 }
  ?>

first edit your method value from post to POST

then edit your action value to be submited at same page if your php code in the same page as metion in your answer

action="<?= $_SERVER['PHP_SELF'] ?>"

finally

you have SQL injection in your query use prepared statement instead

just for cleanup your code delete enctype attribute it used only incase of upload files or images

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM