Save HTML Form Data to a MySQL Database using PHP

Learn how to create a form in HTML, then save the data from that form to a MySQL database using PHP.

For a more detailed version of the techniques shown in this video, check out the full course here: https://skl.sh/3tNX25N

Please consider supporting my channel: https://ko-fi.com/davehollingworth

Recommended hosting:
https://davehollingworth.net/hosting

In this video you’ll learn how to:
– create a form in HTML using best practices
– create form controls for simple text input
– use multi-line text input using the textarea element
– use select lists, radio buttons and checkboxes
– process the submitted form data using PHP
– validate the form data using filter functions
– avoid an SQL injection attack
– use a prepared statement to insert a new record into a database
– create a database and table using phpMyAdmin
– use an SQL INSERT INTO statement to insert a record

Code shown in the video:
https://gist.github.com/daveh/c5a691136c7e3b81dc8e72b3fc1054b3

Relevant documentation:
https://developer.mozilla.org/docs/Web/HTML/Element/input
https://developer.mozilla.org/docs/Web/HTML/Element/textarea
https://www.php.net/manual/filter.filters.validate.php
https://www.php.net/manual/mysqli-stmt.bind-param.php#refsect1-mysqli-stmt.bind-param-parameters
https://www.mysqltutorial.org/mysql-data-types.aspx

00:00 Introduction
00:15 Create the HTML file
01:09 Simple text input
01:38 Labels
02:34 Textarea
03:19 Styling with CSS
04:19 Lists
05:49 Radio buttons
07:36 Fieldset
08:34 Checkbox
09:28 Create the PHP file
11:47 Get the form data
12:55 Filter the data
15:04 Validate the data
16:00 Create the database
16:12 Create the table
17:08 Connect from PHP
19:50 Write the SQL
20:32 SQL injection attack
21:00 Prepared statement
22:08 Bind values to placeholders
23:42 Insert the data
24:06 Summary

#HTML #PHP #MySQL #forms

Source: https://www.youtube.com/watch?v=Y9yE98etanU

Leave a Reply

Your email address will not be published. Required fields are marked *