I have a button. When I press a button, one number reduces the number in the data base. I want when pressed each time it reduces the number by one
code html & php
<form method="post">
<div><?php
$username = "root";
$password = "";
$database = new PDO("mysql:host=localhost; dbname=testt;",$username,$password);
$ser = $database->prepare("SELECT * FROM test");
$ser->execute();
foreach ($ser AS $res){
echo '<h1>' . $res['NUMBER']; '</h1>';
}
?></div>
<input type="submit" name="click" value="click" id="click">
</form>
<?php
if (isset($_POST['click'])){
$username = "root";
$password = "";
$database = new PDO("mysql:host=localhost; dbname=testt;",$username,$password);
$tet = 12;
$update = $database->prepare("UPDATE test SET NUMBER=$tet-1 WHERE ID = 1");
$update->execute();
}
?>
My Answer:
Here is an example of HTML and PHP code that achieves the functionality you described:
HTML:
html
Reduce Number
Number:
PHP (reduce_number.php):
php
$number = $_POST['number'];
$number = $number - 1;
// Update the number in the database here
echo $number;
?>
In this code, when the "Reduce Number" button is clicked, an AJAX request is sent to the `reduce_number.php` file with the current number as a parameter. The PHP script then reduces the number by 1 and updates the number in the database. Finally, the updated number is sent back to the HTML page and displayed to the user.
Rate this post
4 of 5 based on 8418 votesComments