So a have the below piece of code which i am trying to cut down the top section of code into just having one SQL query which is being ran with a different database record being affected each time (the id just needs to be changed each time).
Any help is appreciated, or links to sources where I can learn how to do this myself as I don't seem to be able to google the right thing :(
<!DOCTYPE html>
<html>
<head>
<?php
require_once 'db.php';
if(isset($_POST['cyanxerox'])){
$sth = $conn->prepare("UPDATE supplies SET quantity = quantity + 1 WHERE Id=1");
$sth->execute();
header('Location: index.php');
die("Posted, now redirecting");
}
if(isset($_POST['magentaxerox'])){
$sth = $conn->prepare("UPDATE supplies SET quantity = quantity + 1 WHERE Id=2");
$sth->execute();
header('Location: index.php');
die("Posted, now redirecting");
}
if(isset($_POST['blackxerox'])){
$sth = $conn->prepare("UPDATE supplies SET quantity = quantity + 1 WHERE Id=3");
$sth->execute();
header('Location: index.php');
die("Posted, now redirecting");
}
if(isset($_POST['yellowxerox'])){
$sth = $conn->prepare("UPDATE supplies SET quantity = quantity + 1 WHERE Id=4");
$sth->execute();
header('Location: index.php');
die("Posted, now redirecting");
}
?>
<title>Homepage</title>ss" href="style/
<link rel="stylesheet" type="text/cmain.css">
</head>
<body>
<h1>ICT Support Printer Supplies Inventory</h1>
<form method="POST" action="index.php">
<input type="submit" name="cyanxerox" value="Cyan Xerox"/>
</form>
<form method="POST" action="index.php">
<input type="submit" name="magentaxerox" value="Magenta Xerox"/>
</form>
<form method="POST" action="index.php">
<input type="submit" name="blackxerox" value="Black Xerox"/>
</form>
<form method="POST" action="index.php">
<input type="submit" name="yellowxerox" value="Yellow Xerox"/>
</form>
$_POSTvariables to be set?