|
1 | 1 | # Database Form
|
| 2 | + |
2 | 3 | PHP example demonstrating how to post form data into a MySQL database and display it.
|
| 4 | + |
| 5 | +**NOTE**: This is only one of many methods one may want to do this. Please research further to see if this example suits your needs. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +* PHP ~v5.6+ |
| 10 | + * PDO extension enabled |
| 11 | +* MySQL ~v5.6+ |
| 12 | + |
| 13 | +**NOTE**: These are the version the example has been tested under. |
| 14 | + |
| 15 | +## Setup |
| 16 | + |
| 17 | +* Configure `config.php` to meet your own mysql connection parameters. |
| 18 | +* Create a database with the same name as the constant `DB` (default: **php-db-form**) in `config.php` and import `database.sql` to it. |
| 19 | + |
| 20 | +## How it works ? |
| 21 | + |
| 22 | +This is easy. The `index.php` connects to the database and loads all emails within the table `emails` and displays them. |
| 23 | +Additionally there is a input field, where new emails can be appended to the `emails` table. |
| 24 | + |
| 25 | +When a new email added, the form is submitted to `actions.php` where the action `add` is mapped to connect to the database and insert a new email in the `emails` table. |
| 26 | +If an error occurs, then the script redirects back to `index.php` with an `error` GET parameter, containing an error message. |
| 27 | + |
| 28 | +## Troubleshooting |
| 29 | + |
| 30 | +If you are having any troubles, create an issue here on GitHub. |
| 31 | + |
| 32 | +## Licence |
| 33 | + |
| 34 | +[The BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) (BSD-3-Clause) |
0 commit comments