The kindest evening. Can you tell me how to implement the approval and delete buttons from the site? I only thought of this:

<form method="POST"> <input type="hidden" name = "new_cat" value="<?php echo $row['id'] ?>"> <input type="submit" name="submit" value="Отправить"> </form> <?php $data = $_POST; if (isset($data['submit'])) { $sql = ("UPDATE `films` SET `fpublic` = '1' WHERE `id`=".$data['new_cat']); $result = $pdo->prepare($sql); $result ->execute(); } ?> 

To cling on two forms to each post is somehow not logical. Yes, and the page does not work correctly: Click on the button, the page reloads, everything remains unchanged, reload the page itself, a window appears confirming the resubmission of data, and then the post is published.

So what is the easiest way to implement these two buttons for posting and deleting a post?

  • in the example there is only one button. publish all the code in question. - webDev_
  • I showed the example of a single button. - gm-111
  • Why do you need a form at all? Links with the same information are not satisfied? On the client, check the confidence of the action (js onConfirm ()), on the server, access to the methods, and redirext back to the page. - Bookin

3 answers 3

 <a href="?id=1">Обновить</a> 

In handler

 <?php if (isset($_GET['id'])) { $id = $_GET['id']; // Здесь делаете запрос БД header('Location: /'); // Переадресация на нужную страницу exit(); } 
  • This option suits me. Thank you .. - gm-111

POST to another page. There produce UPDATE and through

 header("Location: ..."); 

return to the original page.

    Maybe I say not the optimal solution, but the most adequate option is to do it not by form. You make 2 buttons, because the different meaning of the buttons. You hang up a handler on clicks of JavaScript or even JQuery, as you like, and with the help of AJAX you send it to a PHP page, the necessary operation takes place there, the adequacy check is done and a response is given. Depending on this answer, the result of success or failure is already displayed on your page ...

    The plus of what I am saying is that you will control everything without a reboot, and the result will be as adequate as possible. The minus of my approach is that if suddenly the same user with JavaScript turned off in the browser, he won’t be able to do anything (for me it is irrelevant, in 95% of cases it is enabled), and there are more pluses than minuses.

    • The option is good, but the Ajax are not familiar to me. - gm-111