Question: Table Creation Open phpMyAdmin and: Open your database named serverside Create a tweets table with the following columns: id (Integer. Auto-incrementing primary key) status (Var
Table Creation
Open phpMyAdmin and:
- Open your database named serverside
- Create a tweets table with the following columns:
- id (Integer. Auto-incrementing primary key)
- status (Var Char of length 140)
- Add two rows to this table using the phpMyAdmin interface.
Required Documents
Start by creating three documents:
- index.php (Top PHP block plus valid HTML markup.)
- insert.php (Top PHP block plus valid HTML markup.)
- connect.php (PHP only.)
R is for Read
In your connect.php file:
- Define constants for your DB user, password and database.
- Use these constants to connect to your DB by creating a PDO object called $db. (See the notes for an example of how to do this.)
In the PHP block at the top of your index.php file:
- Connect to your database by requiring your connect.php file.
- Query the tweets table for all rows.
In the markup within your index.php file:
- If the select query at the top of your document return no rows:
- display a message indicating that there are no tweets.
- If the select query at the top of your document return one or more rows:
- create an unordered list element (ul).
- Within the unordered list, loop through and display all tweets with li elements.
Testing:
- Ensure that when you view your index.php file you see the two tweets that are already in your database.
- Ensure that your markup is valid.
- Remove the two tweets from your tweets table (using phpMyAdmin):
- Ensure that the No tweets found message is now displayed.
- Ensure that your markup is still valid.
C is for Create
In the markup within your index.php file:
- Add a form with the following elements:
- Label element for your input element
- Input element for tweets
- Submit button
- Ensure that the form POSTs its data to your insert.php document.
In the PHP block within your insert.php file:
- Extract the data POSTed from index.php into variables.
- If the users tweet is empty or longer than 140 characters:
- display an appropriate error message within the markup portion of this file.
- If the users tweet is 1 to 140 characters in length (inclusive):
- Connect to your database using the connect.php file.
- Insert the tweet into the tweets table.
- Redirect the user back to the index.php using the header function.
- Exit the script using the exit method.
Testing:
- Ensure that your index.php markup is still valid.
- Ensure that when your tweet is empty or longer than 140 characters the markup generated by the insert.php file is valid.
- Ensure that you can add tweets to your tweets table using your scripts.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
