Beginners PHP and MySQL (2)

Source: Internet
Author: User
Tags html page mysql php and php and mysql

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>
&LT;TD align=center bgcolor= #00FFFF >idx</td>
&LT;TD align=center bgcolor= #00FFFF >user name</td>
&LT;TD align=center bgcolor= #00FFFF >last name</td>
&LT;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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.