Exercise #6
-
Make sure you have webserver w/ PHP support and a database, such as MySQL or MariaDB, installed.
-
Populate the
config.phpto connect to your database and create a$myconnresource handle to be used in the following two scripts. Do not put anything else in theconfig.php. -
Create a PHP script called
newdb.phpthat would make queries to the database and (re)create a table called'messages'that has the following columns:
Column Description idAn auto-incremented integer, which is also the primary key. titleA variable length string up to 100 characters, default of empty string mesgA text field, default should be the empty string dateA timestamp, default should be CURRENT_TIMESTAMP()
The script output should also include a query to populate the message table with a default message.
NOTE: This script should use the PHP mysqli interface (as should the next script,) to create and populate the table. It should not just output SQL commands for the mysql client command.
-
Create a script called
mboard.phpthat should use the display the same kind of message board as with exercise 5 (refer to exercise 5 for more information,) however, this time using the database you created withnewdb.php.The
mboard.phpshould have a form that posts to itself in order to add another message to the message table.These scripts should use the PHP mysqli as described in lesson 6. You should use prepared statements whenever a query requires inputs. Do use
htmlspecialchars()on all data strings received from the user.