PHP MYSQL HTML

SAVE HTML FORM INTO DATABASE WITH PHP MYSQL

SIMPLE "SURVEY" TABLE email | varchar(255) PRIMARY KEY name | varchar(255) color | varchar(128)

DATABASE TABLE

01

PROCESS SAVE ON SUBMIT <?php if (isset($_POST["email"])) { require "save.php"; } ?>

HTML FORM

02

FORM ITSELF <form method="post">   <input type="email" name="email"/>     <input type="text" name="name"/>    <input type="text" name="color"/>    <input type="submit" value="Go!"/> </form>

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

SAVE INTO DATABASE (A)

03

SAVE INTO DATABASE (B)

04

PREPARE SQL $stmt = $pdo->prepare("   INSERT INTO `survey`   (`email`, `name`, `color`)   VALUES (?, ?, ?)" );

SAVE INTO DATABASE (C)

05

INSERT HTML FORM $stmt->execute([     $_POST["email"],   $_POST["name"],     $_POST["color"] ]);