gotFusion.com....... Where your adventure begins
Full Service Web HostingNetObjects Fusion 7 Websites Portal

 


 

On This Page

Choose the Pet

Display Form

Update the Database

All the Examples on this page can be found in the php sample site

 

In This Tutorial

MySQL--Getting Started

SELECT Statements

Forms

On All Forms

Forms-Add

Forms-Update

Forms-Delete

Combo Boxes

Choosing the Pet to Update

In this simple database example, if we want to edit a particular pet, we must first choose that pet. In this example, we will make our box a multi-list box of all pets in the database instead of a pulldown. You can switch back and forth easily. Both styles are populated the same way. For more on populating combination boxes, see the Combo Boxes Page.

  
What does the page look like?

Some PHP code required in order to retrieve the list of Pets:

Open the database and select pets if there are any

In order to actually get the form to pull up that pet's information, choose the pet, click the "EDIT" submit button and the form will got to the next Update Pet Page, pupdate2.php, which actually contains the form to update the pet. To do this, we make the form's action the next Update Pet Page:

Selecting a pet form calls the next form, update2.php


Displaying the Form with the Pet Information:

The Form is very similar to the Add a New Pet Form except there are "values" inside the text area of each field:

form to update the pet

The form will call pupdate3.php which will perform the actual database update. Note that the table column "petid" is passed hidden. This is to ensure that the next page will be able to use it even though it is not displayed in the form and the user never sees it.

pass the pid as a hidden field, call phpupdate3.php

If you look, you'll notice that the form to add a pet does not have the hidden field petid. Why? Because the petid is determined when the record is actually inserted into the database, not by the user :) (cool!).


Updating the Database

We again connect to the server and open the database. Pupdate3.php is clean and simple, showing only the text box containing the php code to update the table and links.

pupdate3.php contains php code and links only

If the Pet name is not blank, we can update the information in the table.

open db, check pet name, update table

Converting integer strings:
HTML form text fields have a tendency to convert non-text values to "text" datatypes. Saving "text" datatypes into a MySQL column that should contain numeric data will cause the SQL statement to fail. The reason for the datatype conversion may be server based, database based, or a PHP version issue. The issue seems to be intermittant, based on PHP configurations, MySQL database setup, and operating system the application is running under, but it does occur often enough to be a nuisance. In order to prevent running into this, it is a good idea to perform a SETTYPE on any integer, logical, or Double datatypes that have been editted via an HTML form before inserting or updating into the database.

next lesson - Deleting Records

View the PREVIOUS page in this tutorial

Return to the TOP of this page

View the NEXT page in this tutorial


|  Fusion  |  Web Design  |  Hosting  |  Resources  |  gotFusion Store  | 

Problems with this page?  

All content copyright © 2002 gotFusion LLC.  The name gotFusion and the gotFusion ® logo are registered trademarks of gotFusion LLC
Copyright, legal notice & privacy statement