I'm a bit of a noob at php/sql (well all languages in general), I am trying to get an sql command to run on the click of a html button.
The sql command that I am trying to run is UPDATE supplies SET quantity = quantity + 1 WHERE Id=1
This is what I have at the moment:
dp.php
<?php
$servername = "localhost";
$dbname = "tonor";
$username = "root";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
index.php
<!DOCTYPE html>
<html>
<head>
<?php
require_once 'db.php';
if(isset($_POST['data'])){
$sth = $conn->prepare("UPDATE supplies SET quantity = quantity + 1 WHERE Id=1");
$sth->execute();
}
?>
<title>Homepage</title>
<link rel="stylesheet" type="text/css" href="style/main.css">
</head>
<body>
<h1>testpage</h1>
<form method="POST" action="index.php">
<input type="submit" name="data" value="1"/>
</form>