ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

PHP, SQL, insert from HTML input

No regards to the SECURITY!, this code only explains how the data entered into the database via HTML input .

PHP code

// set up the connection with the database
$conn = new PDO("mysql:host=localhost;dbname=learndb", "root", "");

// gets the input from the FORM and asig it as a variable to passed as VALUE TO THE VALUES
$name = $_POST['name'];

// Setup the query
$sql = "INSERT INTO people (name) VALUES ('$name')";

// execute the query

// close the connection with the database
$conn = null;


HTML code

<!-- form, sets method and sends the data to be inserted into the database -->
<form action="insert.php" method="POST">

<!-- data input -->
<input type="text" name="name"><br>

<!-- submits the form -->
<input type="submit" value="Submit">

back-end , PHP