In the future, please put in an appropriate title in your question. That helps us motivated people to answer questions with an appropriate title. This is just basic, courteous net etiquette.
What follows is a skeleton of what you need to do. I will not supply the entire solution but leave it up to you to think and solve your own problem. That way, you will learn in the process.
First, the form (frmSoccer.htm)
<form name="frmSoccer" action="insertData.php" method="post">
<table>
<tbody>
<thead>
<tr>
<td>User</td>
<td>Character name</td>
<td>Item</td>
<td>Item Details</td>
<td>Price</td>
</tr>
</thead>
<tr>
<td><input type="text" name="txtuser value=""/></td>
<td><input type="text" name="txtCharacterName value=""/></td>
<td><input type="text" name="txtItem value=""/></td>
<td><input type="text" name="txtItemDetails value=""/></td>
<td><input type="text" name="txtPrice" value=""/></td>
<td><input id="btnSubmit" type="submit" value="submit" /></td>
</tr>
</tbody>
</table>
</form>
Second, the php code to insert (insertData.php)
<?php
// if there was not a button pressed, don't bother
if !isset($_POST['btnSubmit']) {
return;
}
// retrieve the data and store in PHP variables
$user = $_POST['txtUser'];
$characterName = $_POST['txtCharacterName'];
$item = $_POST['txtItem'];
$itemDetails = $_POST['txtItemDetails'];
$price = $_POST['txtPrice'];
// validate the data
// make sure the data is clean, well formed and makes sense
// otherwise garbage will be stored in the database
// (the code i'll leave that up to you)
// Store your posted data in mysql database
// 1) Connect to mysql
// 2) Build query string to insert
// 3) Close the connection
$hostname = "localhost, or the ip address of the mysql server";
$username = "your-mysql-admin-accountname";
$password = "your-mysql-admin-password";
$dbName = "your-database-name";
$dbTablename = "your mysql table name";
$db = mysql_connect($hostname, $username, $password);
mysql_select_db($dbName, $dbTablename);
$sql = "the SQL INSERT statement and your values from the data variables above";
$queryResult = mysql_query($sql, $db);
mysql_close($db);
// Regenerate the page
// 1) Connect to mysql
// 2) Build query string to show "n" records
// 3) Iterate over the "n" records and display in a table
// 4) Close the connection
$db = mysql_connect($hostname, $username, $password);
mysql_select_db($dbName, $dbTablename);
$sql = "the SQL SELECT statement and your values from the data variables above";
$queryResult = mysql_query($sql, $db);
if (mysql_num_rows($queryResult) == 0) {
echo "No records found";
return;
}
echo "<table class='tblResults'>";
while ($row = mysql_fetch_assoc($queryResult)) {
echo "<tr>";
echo "<td>" . $row["user"] . "</td>";
echo "<td>" . $row["characterName"] . "</td>";
echo "<td>" . $row["item"] . "</td>";
echo "<td>" . $row["itemDetails"] . "</td>";
echo "<td>" . $row["price"] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($db);
?>
- You will need to bone up on mysql and learn how to setup a user account and database.
- You will also need to bone up on SQL, in particular the INSERT and SELECT statements.
Note that the row variables ($row["user"], ... $row["price"]) correspond to actual column names in your database table.
Also note that the POST variables retrieved from the form itself correspond to each individual form element's name.
$user = $_POST['txtUser'];
$characterName = $_POST['txtCharacterName'];
$item = $_POST['txtItem'];
$itemDetails = $_POST['txtItemDetails'];
$price = $_POST['txtPrice'];
Obviously, it is difficult to walk someone through an entire solution if you don't have basic knowledge of PHP, MySql, SQL. I would suggest getting a few books and reading through them to assist you.
Good luck and I'll take a pint of Guinness 😃