JavaScript
, , JavaScript
, .
MySQL
, - :
CREATE TABLE Items(
ItemID INTEGER AUTO_INCREMENT PRIMARY KEY,
Description VARCHAR(255),
IsReserved TINYINT(1) //this works like a boolean
);
, :
SELECT * FROM Items ORDER BY ItemID
:
$server = "localhost";
$username = "root";
$password = "root";
$database = "mydatabase";
$connection = mysqli_connect($server, $username, $password, $database);
$result = mysqli_query($connection, "SELECT * FROM Items ORDER BY ItemID");
if (mysqli_num_rows($result) > 0){
echo("<form action=\"mypage.php\" method=\"post\">");
while($row = $result->fetch_assoc()){
echo("input name=\"id\" type=\"hidden\" value=" . $row['ItemID'] . ">");
echo("ID: " . $row['ItemID']);
echo("Description: " . $row['Description']);
if ($row['IsReserved'] == 1){
echo("<button class=\"mybutton\" type=\"submit\" disabled>Reserve</button>");
}
else{
echo("<button class=\"mybutton\" type=\"submit\">Reserve</button>");
}
}
echo("</form>");
}
else{
echo("No data");
}
, , , โโ PHP
, - :
$server = "localhost";
$username = "root";
$password = "root";
$database = "mydatabase";
$connection = mysqli_connect($server, $username, $password, $database);
$id = (int) $_POST['id'];
mysqli_query($connection, "UPDATE Items SET IsReserved = 1 WHERE ItemID = $id");
mysqli_close($connection);
, , , :)
I will leave you this guide on how to process forms and their data using PHP
.
source
share