Hello and welcome to Module 10. How to use PHP to add data to a MySQL database. In phpMyAdmin, make a table first. You can set up columns (name, type, etc.) in phpMyAdmin. For example, VARCHAR for text or INT for numbers. Use MySQLi or PDO to link PHP to MySQL. PDO works with many different types of databases, but MySQLi only works with MySQL. Both use prepared statements to keep SQL injection from happening. Use cPanel credentials to test the connection with a new mysqli(…) script. Make an HTML form that has the same fields as your table (first name, last name, email) and send it to insert.php. Use $_POST to get input in insert.php and run an INSERT query, preferably with prepared statements. Before deploying, always check and clean up input, handle errors, close the connection, and update scripts with your account information
Leave a comment