Student developer here working on an assignment that involves php and sql. The objective of the assignment is as follows: collect user data through a form and use php to validate and insert information into a mysql table. The table that is storing user information has strictly four fields, firstName, lastName, phoneNumber, birthdate just as the form has four fields. Provide the user with a link on the form page that takes them to another page which displays a temporary table of all the users that have submitted their information through this form. In addition to this data it should also display a few more fields including:
- the area code as a sub string
- eligibility status (eligibility status is yes if the area code is 425) otherwise no
- birth month
- birthstone The birth month and birthstone should be pulled from a two dimensional array using the sub string function and the date of birth fields to accomplish this. January Garnet February Amethyst March Aquamarine April Diamond May Emerald June Pearl July Ruby August Peridot September Sapphire October Opal November Topaz December Tanzanite
- At the top of the temporary table is a statement that says "As of today, (current date should be displayed), The following participants are registered. I have managed to validate the data and insert it into a table. Beyond that is where I am having trouble, starting from querying the database to display the temporary table. How do I return the data that's in a table and how do I display it? Should I make a table using HTML and then display database information in that table? If so, how do I go about doing this?
I am not quite sure where to start, though I have tried to retrieve the data from the database and display it. I tried to use mysqli_fetch_assoc to retrieve some data, I managed to retrieve some of it but I do not know how to display it the way the assignment is asking.
<?php
$dbConnect = @mysqli_connect("localhost", "user", "password")
or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>";
$dbName = 'Competition';
// selects the database
$QueryResult = mysqli_select_db($dbConnect, $dbName);
if (!$QueryResult) {
echo "cannot connect to this database";
}
$TableName = "Competitors";
$sqlString = "SELECT * FROM $TableName";
$QueryResult = @mysqli_query($dbConnect, $sqlString)
or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>";
while ($row = mysqli_fetch_assoc($QueryResult)) {
$FirstName = $row['firstName'];
$LastName = $row['lastName'];
$PhoneNumber = $row['phone'];
$Birthdate = $row['birthday'];
echo $FirstName . $LastName . $PhoneNumber . $Birthdate . "<br>";
}
// closing the connection with the database server
mysqli_close($dbConnect);