There is a request of the form
UPDATE `gb_ptich` SET `pay_status` = REPLACE(`pay_status`, '0', '1') you need to run it when clicking on the link <a href="#">Обновить</a>
How to do this through PHP?
There is a request of the form
UPDATE `gb_ptich` SET `pay_status` = REPLACE(`pay_status`, '0', '1') you need to run it when clicking on the link <a href="#">Обновить</a>
How to do this through PHP?
You can do the following: let the form be located in the index.html file and contain the client part of the gadget (link and AJAX binding for it)
<!DOCTYPE html> <html lang='ru'> <head> <title>Обновление таблицы</title> <meta charset='utf-8'> <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js" > </script> <script type="text/javascript"> // Назначить обработчики события click // после загрузки документа $(function(){ $("a").on("click", function(){ // Отправляем AJAX-запрос $.post("handler.php"); }) }); </script> </head> <body> <a href="#">Обновить</a> </body> </html> As you can see, the AJAX request is sent to the file handler.php, which may contain the following code, to execute the UPDATE request (using the PDO extension)
<?php try { $pdo = new PDO( 'mysql:host=localhost;dbname=test', 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $query = "UPDATE `gb_ptich` SET `pay_status` = REPLACE(`pay_status`, '0', '1')"; $pdo->exec($query); header('location: /'); exit(); } catch (PDOException $e) { echo "Ошибка выполнения запроса: " . $e->getMessage(); } ?> $.post - Mr. BlackSource: https://ru.stackoverflow.com/questions/534695/
All Articles