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 $conn->exec($sql); // 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"> </form>
19 Related pages
- About PHP
- php Convert Bytes To KB, MB, GB
- PHP date and time
- php define path to dir
- PHP display all images from a folder
- PHP get image as function
- php image upload
- php image width and height
- PHP list all files in directory and subdirectories
- PHP list all image with info
- php list files as array
- php list files with similar name regardless of file extension
- php search for file by name without file extension
- PHP send and catch data
- php strip tags
- php url full path
- php, list all file and folder from dir without file extension
- PHP, SQL, insert from HTML input
- WordPress page conditions front page