| |
|
|
|
Home: Tutorials: Adding Records to Your Database Using PHP, Part 1: The Insert Form Adding Records to Your Database Using PHP, Part 1: The Insert FormIntroductionThis lesson is the first of two tutorials that will examine how to create an insert form using MySQL and PHP. In Part 1, we will examine the code needed to allow the user to enter and submit. Then, in Part 2, we will look at a PHP script that inserts that data into a MySQL database. Setting Up a Search FormThe code for creating a form that allows user to add to a MySQL database via a web browser is quite simple (especially for those familiar with HTML). Here, for example, is the insert form for the categories section of the 4D web site:
‹html›
‹head›
‹title›4d Categories Insert New Entry : Views‹/title›
‹/head›
‹body›
‹h1›4d Categories Insert New Entry‹/h1›
‹form action="4d_categories.php" method="post"›
‹table border=0›
‹tr›‹td›catNum‹/td›‹td› ‹input type=text name=catNum maxlength=1000 size=50›‹br›‹/td›‹/tr›
‹tr›‹td›catName<‹/td›‹td› ‹input type=text name=catName maxlength=500 size=50›‹br›‹/td›‹/tr›
‹tr›‹td colspan=2›‹input type=submit value="add categories entry"›‹/td›‹/tr›
‹/table›
‹/form›
‹/body›
‹/html›
As you can see, the insert form includes two text fields where the two fields of the catgegory entry are entered and a standard submit button. More importantly, one should note: - The action point not to a CGI-script, as a typical form, but to a file with a .php extension called 4d_categories.php. This file, which we will look at in the next tutorial, contains the script that will insert the user’s entry into the categories database.
- The input names for the text fields are catName and catNum. These correspond to the two fields of the categories database. The values entered by the user are passed to the php script (4d_categories.php) when the user hits submit.
Looking ForwardWith our insert form written, the next steps will be to capture the insert data, connect to the database, insert the data and give feedback to the user that the insertion is successful. Read on to the next tutorial, Adding Records to Your Database Using PHP, Part 2: The PHP Script to review these concepts. |
|