PHP MYSQL HTML

SIMPLE ORDER FORM WITH PHP MYSQL

(quick guide & example)

ORDER DATABASE TABLE

01

order_id name email qty

INTEGER PRIMARY KEY VARCHAR VARCHAR INTEGER

<form method="post" target="_self">    <input type="text" name="name">    <input type="email" name="email">    <input type="number" name="qty"">   <input type="submit" value="GO!">  </form>

HTML ORDER FORM

02

CONNECT TO DATABASE $pdo = new PDO("mysql:host=HOST; dbname=NAME;charset=utf8",  USER, PASSWORD); 

PHP SAVE ORDER

03

SAVE INTO DATABASE $stmt = $pdo->prepare("INSERT INTO `orders` (`name`, `email`, `qty`) VALUES (?,?,?)"); $stmt->execute([$_POST["name"], $_POST["email"], $_POST["qty"]]);