title: HTML button to run SQL command
body: <p>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.</p>
  
  <p>The sql command that I am trying to run is <code>UPDATE supplies SET quantity = quantity + 1 WHERE Id=1</code></p>
  
  <p>This is what I have at the moment:</p>
  
  <p>dp.php</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $dbname = "tonor";
  $username = "root";
  $password = "password";
  
      try {
          $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
          $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      } catch(PDOException $e) {
          echo "Connection failed: " . $e-&gt;getMessage();
      }
  ?&gt;
  </code></pre>
  
  <p>index.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;?php 
          require_once 'db.php';
  
          if(isset($_POST['data'])){
              $sth = $conn-&gt;prepare("UPDATE supplies SET quantity = quantity + 1 WHERE Id=1");
              $sth-&gt;execute();
          }
      ?&gt;
      &lt;title&gt;Homepage&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="style/main.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;testpage&lt;/h1&gt;
      &lt;form method="POST" action="index.php"&gt;
          &lt;input type="submit" name="data" value="1"/&gt;
      &lt;/form&gt;
  </code></pre>