Assuming you are familiar with the form, this is a fairly simple script. We designed a form based on an HTML page that is invoked after committing
ADD2TBL.PHP3 script. Now, the form and the MySQL table should be composed of 4 fields: Index Number,firstname,lastname and
FreeText. Note that the field name in this form is the same as the field name in the MySQL table, but this is only for convenience rather than necessity.
We have once again used the include command. Include (' links.x ');? > (as explained earlier) to add links.
Let's take a look at the add2tbl.php3 script:
<body>
?
if ($UserName)
{
Mysql_connect () or Die ("Problem Connecting to DataBase");
$query = "INSERT into TBL values (' $idx ', ' $UserName ', ' $LastName ', ' $FreeText ')";
$result = Mysql_db_query ("Example", $query);
echo "Data inserted. New Table:<br><p></p> ";
$query = "SELECT * from TBL";
$result = Mysql_db_query ("Example", $query);
if ($result)
{
echo "<table width=90% align=center border=1><tr>
<TD align=center bgcolor= #00FFFF >idx</td>
<TD align=center bgcolor= #00FFFF >user name</td>
<TD align=center bgcolor= #00FFFF >last name</td>
<TD align=center bgcolor= #00FFFF >free text</td>
</tr> ";
while ($r = Mysql_fetch_array ($result))
{
$idx = $r ["idx"];
$user = $r ["UserName"];
$last = $r ["LastName"];
$free = $r ["FreeText"];
echo "<tr>
<td> $idx </td>
<td> $user </td>
<td> $last </td>
<td> $free </td>
</tr> ";
}//While Loop end
echo "</table>";
}
Else
{
echo "No data."
}//If End ($result)
}
Else
{
echo "No UserName entered. Please go back and reenter UserName ";
}//If End ($UserName)
echo "<p></p>";
Include (' links.x ');
?>
</body>
Explain:
This section contains two main sections. The first part gets the data from the previous form and inserts them into the database. Part II
Print out the contents of the table from the database. The second part is the same as I demonstrated in the view of the database section.