Anda di halaman 1dari 50

NOTA PHP

Menggunakan Adobe Dreamweaver

DISEDIAKAN OLEH

Arif Wahab

INTRODUCTION What is PHP PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Simple answer, but what does that mean? An example: An introductory example <html> <head> <title>Example</title> </head> <body> <?php echo "Hi, I'm a PHP script!"; ?> </body> </html> Notice how this is different from a script written in other languages like Perl or C -instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something (in this case, output some text). The PHP code is enclosed in special start and end tags that allow you to jump into and out of "PHP mode". What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server. If you were to have a script similar to the above on your server, the client would receive the results of running that script, with no way of determining what the underlying code may be. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve. The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid reading the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours. Although PHP's development is focused on server-side scripting, you can do much more with it. Read on, and see more in the What can PHP do? section, or go right to the introductory tutorial if you are only interested in web programming.

What can PHP do Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more. There are three main areas where PHP scripts are used. Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work. The PHP parser (CGI or server module), a webserver and a web browser. You need to run the webserver, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming. See the installation instructions section for more information.

Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about Command line usage of PHP for more information. Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit its own website. PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. For the majority of the servers PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor. So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object oriented programming, or a mixture of them. Although not every standard OOP feature is implemented in PHP 4, many code libraries and large applications (including the PEAR library) are written only using OOP code. PHP 5 fixes the OOP related weaknesses of PHP 4, and introduces a complete object model.

With PHP you are not limited to output HTML. PHP's abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content. One of the strongest and most significant features in PHP is its support for a wide range of databases. Writing a database-enabled web page is incredibly simple. The following databases are currently supported: Adabas D DBase Empress Hyperwave IBM DB2 Informix Ingres InterBase FrontBase mSQL MySQL ODBC Oracle (OCI7 and OCI8) Ovrimos PostgreSQL SQLite Solid Sybase Velocis Unix dbm

FilePro (read-only) Direct MS-SQL

We also have a DBX database abstraction extension allowing you to transparently use any database supported by that extension. Additionally PHP supports ODBC, the Open Database Connection standard, so you can connect to any other database supporting this world standard. PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects. You can also use our CORBA extension to access remote objects. PHP has extremely useful text processing features, from the POSIX Extended or Perl regular expressions to parsing XML documents. For parsing and accessing XML documents, PHP 4 supports the SAX and DOM standards, and you can also use the XSLT extension to transform XML documents. PHP 5 standardizes all the XML extensions on the solid base of libxml2 and extends the feature set adding SimpleXML and XMLReader support. While using PHP in the e-commerce field, you'll find the Cybercash payment, CyberMUT, VeriSign Payflow Pro and MCVE functions useful for your online payment programs.

At last but not least, we have many other interesting extensions, the mnoGoSearch search engine functions, the IRC Gateway functions, many compression utilities (gzip, bz2), calendar conversion, translation... As you can see this page is not enough to list all the features and benefits PHP can offer. Read on in the sections about installing PHP, and see the function reference part for explanation of the extensions mentioned here.

What you need to build web applications To build web applications in Dreamweaver, you need the following software:

A web server An application server that runs on your web server, or a web server that doubles as an application server, such as APACHE

Note: In the context of web applications, the terms web server and application server refer to software, not hardware. If you want to use a database with your application, you need the following additional software:

A database or database system A database driver that supports your database

How Web Servers Work

PART 1: Installing WAMP WINDOWS, APACHE, MYSQL AND PHP Introduction WAMP5 is an installer for Windows. it installs a complete WAMP solution on your computer. WAMP is for : Windows - Apache - MySQL- PHP5 WAMP5 automatically configures them to work together, wherever you install them on your local drive. These softwares are installed: Apache 2.2.x. PHP 5.x.x MySQL 5.x.x PHPmyadmin SQLitemanager Wampserver service manager WAMP5 comes with a service manager as an icon tray. This manager will allow you to fully control your server and local projects. WAMP5 is not designed for production but as a development environment. With WAMP5, you will be able to create you scripts locally on your computer, test them and then upload them on your production server. We have configured Apache and MySQL servers with default configuration files to have the most standard platform. You can then adapt it to your personal needs. During installation, a "www" directory is created in WAMP5's directory. Just put your script files (php files) in this directory and access your localhost threw an Internet Windows or the service manager (icon tray). WAMP5 requires one of these systems to work: Windows XP, NT, 2000, 2003 How To Install Download the latest release of WAMP5 on one of the WAMPSERVER sites: http://www.wampserver.com/en/

Double-click on the file to start installing. WAMP5 will ask you where to install. You can install wherever you want, WAMP5 builds configuration files to reflect your choice. But don't forget that some scripts and modules don't like long names and special characters like spaces. Process of Installation

1. Click -> NEXT

2. Click -> I accept the agreement 3. Click -> Next

4. Click Next (*Recommended you to leave default directory c:\wamp)

5. Click Next (*Recommended you to leave the default)

WAMP5 will then ask you if want to install the option "Auto Start". If you check this option, services will be installed as automatic and a link to the service manager will be copied to your startup menu. Otherwise, services will be installed as manual and will start and stop with the service manager. 6. Click auto start checkbox to make the services are autostart. 7. Click Next (*Recommended you to click the auto start)

8. Click Install

Installing. Wait until finish.

9. Click Next (*Recommended you to leave the default)

10. Click Open (*Recommended you to leave the default)

11. Click Yes

12. Click Finish Installation finish

After installation. WAMP5's installation is compact. This means that all files are copied to WAMP5's directory. Only the MySQL conf file (usually my.ini) is copied to the Windows directory but as "mywamp.ini" to avoid conflicts with other installs

You just have to click on the icon tray to access WAMP5's menu :

The icon tray reflects the status of your server :

PART 2: DATABASE SQLYOG Introduction SQLyog provides you with powerful means to manage your MySQL databases. SQLyog MySQL GUI is the most popular MySQL Manager and MySQL Admin Tool, combining the features of MySQL Query Browser, phpMyAdmin and various other MySQL Front Ends and MySQL Clients in a single intuitive interface. Installing SQLyog Download the latest version of SQLyog and click the setup file.

1. Click Next

2. Click I accept the terms in the license agreement 3. Click Next

4. Click Next (*Recommended you to leave the default)

Installing wait until finish.

5. Click Finish Finish installing and run the SQLyog. (*Make sure the wamp server is running)

Starting SQLyog Run SQLyog and you will see dialog box as shown below:

After you have connected to an instance of MySQL, you can make additional connections by selecting the New Connection option from the File menu. Select the connection name from the list. To Change the connection, click on the ellipsis button and edit the connection name, click OK button to save the changed connection name. A host name where the database is situated or the IP address of the server. User name for connecting to the database server. Note: This is MySQL username. Not your FTP or webserver username. MySQL user Password Database name. You may enter several database names separated by semicolon (like db1,db2). If you do not enter the database name, all the database names would be listed, to select from. A TCP/IP port for connecting to the database server.

Saved Connections MySQL host address User name Password Databases Port

MySQL Database 1. Intoduction MySQL is a database. A database is a data storage feature. It can be used to store, sort, arrange, and display information. MySQL is a functional feature on it's own. For our tutorials, we will be using PHP commands to use the functions of a MySQL database. 2. Reserved Words Before getting to far into planning, there is a number of words that you cannot use for your table and column names. MySQL uses some specific words for command processing, so using them in your own coding may confuse things a bit. See appendix MySQL-1. 3. Data Type in MySQL Once you have your table data organized, the next step is to figure out the data type. There are three main types : text, numbers, and Dates/Times. Choosing the column types specifies what information can or can't be stored in a table cell. Using the most correct option for each column is important as it may affect the database's overall performance. 3.1 Text Types CHAR( ) VARCHAR( ) TINYTEXT TEXT BLOB MEDIUMTEXT MEDIUMBLOB LONGTEXT LONGBLOB A fixed section from 0 to 255 characters long. A variable section from 0 to 255 characters long. A string with a maximum length of 255 characters. A string with a maximum length of 65535 characters. A string with a maximum length of 65535 characters. A string with a maximum length of 16777215 characters. A string with a maximum length of 16777215 characters. A string with a maximum length of 4294967295 characters. A string with a maximum length of 4294967295 characters.

The ( ) brackets allow you to enter a maximum number of characters will be used in the column. Eg. VARCHAR(20) CHAR and VARCHAR are the most widely used types. CHAR is a fixed length string and is mainly used when the data is not going to vary much in it's length. VARCHAR is a variable length string and is mainly used when the data may vary in length. CHAR may be faster for the database to process considering the fields stay the same length down the column. VARCHAR may be a bit slower as it calculates each field down

the column, but it saves on memory space. Which one to ultimatly use is up to you. Using both a CHAR and VARCHAR option in the same table, MySQL will automatically change the CHAR into VARCHAR for compatability reasons. BLOB stands for Binary Large OBject. Both TEXT and BLOB are variable length types that store large amounts of data. They are similar to a larger version of VARCHAR. These types can store a large piece of data information, but they are also processed much slower. 3.2 Number Types TINYINT( ) SMALLINT( ) MEDIUMINT( ) INT( ) BIGINT( ) FLOAT DOUBLE( , ) DECIMAL( , ) -128 to 127 normal 0 to 255 UNSIGNED. -32768 to 32767 normal 0 to 65535 UNSIGNED. -8388608 to 8388607 normal 0 to 16777215 UNSIGNED. -2147483648 to 2147483647 normal 0 to 4294967295 UNSIGNED. -9223372036854775808 to 9223372036854775807 normal 0 to 18446744073709551615 UNSIGNED. A small number with a floating decimal point. A large number with a floating decimal point. A DOUBLE stored as a string , allowing for a fixed decimal point.

The integer types have an extra option called UNSIGNED. Normally, the integer goes from an negative to positive value. Using an UNSIGNED command will move that range up so it starts at zero instead of a negative number. 3.3 Date Types DATE DATETIME TIMESTAMP TIME YYYY-MM-DD. YYYY-MM-DD HH:MM:SS. YYYYMMDDHHMMSS. HH:MM:SS.

3.4 Misc Types

ENUM ( ) SET

Short for ENUMERATION which means that each column may have one of a specified possible values. Similar to ENUM except each column may have more than one of the specified possible values.

ENUM is short for ENUMERATED list. This column can only store one of the values that are declared in the specified list contained in the ( ) brackets. Eg. ENUM('y','n')

You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted. SET is similar to ENUM except SET may contain up to 64 list items and can store more than one choice. 4. Column Modifier A column modifier is an extra addon command to help the database organize and work better. As mentioned on the previous page, the integer types have an extra option called UNSIGNED. Normally, the integer goes from an negative to positive value. Using an UNSIGNED command will move that range up so it starts at zero instead of a negative number. Other modifier commands are : INDEX, UNIQUE, PRIMARY KEY, AUTO_INCREMENT, NULL, NOT NULL, DEFAULT, BINARY, and ZEROFILL. 4.1 Index Indexing is a way to improve a database performance. You are telling the database that THIS specific column is special and may help organize the data. If there is a column you will be referring to often, it would probably be the best to be an INDEX column. 4.2 Unique and Primary Key An INDEX column may have more than one cell holding the same data value. The two other index types are UNIQUE and PRIMARY KEY. UNIQUE states that each cell in the column should have a unique value. PRIMARY KEY is a special variety of the UNIQUE command. 4.3 Auto Increment The AUTO_INCREMENT modifier works on any of the integer types. Each time a new row is added into the database table, the number in this column will appear and automatically increase by one from the previous row. 4.4 Null NULL is no value. It is not space, it is not zero. A majority of the time you will want to specify a field to be NOT NULL so that any blank entries will be considered as "something".

4.5 Default DEFAULT will assign a default value to a cell if nothing is entered for the value. It will work on most data types except BLOB and TEXT. 4.6 Binary BINARY is used with CHAR and VARCHAR types. It causes the values to be treated as "binary strings" making them CaSe SeNsItIvE. 4.7 Zerofill ZEROFILL is used with numeric data types. It will display leading zeros of a number based on the display width. 5.0 Table Type 5.1 MySQL Architecture It will greatly aid your thinking about storage engines and the capabilities they bring to MySQL if you have a good mental picture of where they fit. Figure 2-1 provides a logical view of MySQL. It doesnt necessarily reflect the low-level implementation, which is bound to be more complicated and less clear cut. However, it does serve as a guide that will help you understand how storage engines fit in to MySQL. (The NDB storage engine was added to MySQL just before this book was printed. Watch for it in the second edition.)

The topmost layer is composed of the services that arent unique to MySQL. Theyre services most network-based client/server tools or servers need: connection handling, authentication, security, etc. The second layer is where things get interesting. Much of the brains inside MySQL live here, including query parsing, analysis, optimization, caching, and all the built-in functions (dates, times, math, encryption, etc.). Any functionality provided across storage engines lives at this level. Stored procedures, which will arrive in MySQL 5.0, also reside in this layer. The third layer is made up of storage engines. Theyre responsible for the storage and retrieval of all data stored in MySQL. Like the various filesystems available for Linux, each storage engine has its own benefits and drawbacks. The good news is that many of the differences are transparent at the query layer. The interface between the second and third layers is a single API not specific to any given storage engine. This API is made up of roughly 20 low-level functions that perform operations such as begin a transaction or fetch the row that has this primary key and so on. The storage engines dont deal with SQL or communicate with each other; they simply respond to requests from the higher levels within MySQL. 5.2 MyIsam

MyISAM is the default storage engine. It is based on the older ISAM code but has many useful extensions. (Note that MySQL 5.0 does not support ISAM.) MyISAM tables have the following characteristics:

All numeric key values are stored with the high byte first to allow better index compression. Dynamic-sized rows are much less fragmented when mixing deletes with updates and inserts. This is done by automatically combining adjacent deleted blocks and by extending blocks if the next block is deleted. The maximum key length is 1000 bytes. This can also be changed by changing the source and recompiling. For the case of a key longer than 250 bytes, a larger key block size than the default of 1024 bytes is used. When rows are inserted in sorted order (as when you are using an AUTO_INCREMENT column), the index tree is split so that the high node only contains one key. This improves space utilization in the index tree. Internal handling of one AUTO_INCREMENT column per table is supported. MyISAM automatically updates this column for INSERT and UPDATE operations. This makes AUTO_INCREMENT columns faster (at least 10%). Values at the top of the sequence are not reused after being deleted. (When an AUTO_INCREMENT column is defined as the last column of a multiple-column

index, reuse of values deleted from the top of a sequence does occur.) The AUTO_INCREMENT value can be reset with ALTER TABLE or myisamchk. Dynamic-sized rows are much less fragmented when mixing deletes with updates and inserts. This is done by automatically combining adjacent deleted blocks and by extending blocks if the next block is deleted. If a table has no free blocks in the middle of the data file, you can INSERT new rows into it at the same time that other threads are reading from the table. (These are known as concurrent inserts.) A free block can occur as a result of deleting rows or an update of a dynamic length row with more data than its current contents. When all free blocks are used up (filled in), future inserts become concurrent again.. You can put the data file and index file on different directories to get more speed with the DATA DIRECTORY and INDEX DIRECTORY table options to CREATE TABLE. BLOB and TEXT columns can be indexed. NULL values are allowed in indexed columns. This takes 01 bytes per key. Each character column can have a different character set. . There is a flag in the MyISAM index file that indicates whether the table was closed correctly. If mysqld is started with the --myisam-recover option, MyISAM tables are automatically checked when opened, and are repaired if the table wasn't closed properly.

MyISAM also supports the following features:


Support for a true VARCHAR type; a VARCHAR column starts with a length stored in one or two bytes. Tables with VARCHAR columns may have fixed or dynamic row length. The sum of the lengths of the VARCHAR and CHAR columns in a table may be up to 64KB.

5.3 InnoDB

InnoDB provides MySQL with a transaction-safe (ACID compliant) storage engine that has commit, rollback, and crash recovery capabilities. InnoDB does locking on the row level and also provides an Oracle-style consistent non-locking read in SELECT statements. These features increase multi-user concurrency and performance. There is no need for lock escalation in InnoDB because row-level locks fit in very little space. InnoDB also supports FOREIGN KEY constraints. You can freely mix InnoDB tables with tables from other MySQL storage engines, even within the same statement. InnoDB has been designed for maximum performance when processing large data volumes. Its CPU efficiency is probably not matched by any other disk-based relational database engine.

Fully integrated with MySQL Server, the InnoDB storage engine maintains its own buffer pool for caching data and indexes in main memory. InnoDB stores its tables and indexes in a tablespace, which may consist of several files (or raw disk partitions). This is different from, for example, MyISAM tables where each table is stored using separate files. InnoDB tables can be of any size even on operating systems where file size is limited to 2GB. InnoDB is included in binary distributions by default. The Windows Essentials installer makes InnoDB the MySQL default storage engine on Windows. InnoDB is used in production at numerous large database sites requiring high performance. The famous Internet news site Slashdot.org runs on InnoDB. Mytrix, Inc. stores over 1TB of data in InnoDB, and another site handles an average load of 800 inserts/updates per second in InnoDB. Creating Database and Table in SQLyog Database name: student Table name: std_info Engine: MyISAM Fields: Fields_Name Datatype std_name varchar std_id double std_address text std_phone_h varchar std_phone_hp varchar std_gender enum std_origin varchar

Len 100

Default 0

Other NOT NULL PK, NOT NULL NOT NULL

15 15 Male,Female 15

Male

NOT NULL NOT NULL

PART 3: ADOBE DREAMWEAVER 1. Defining Site Organizing the site structure Break down your site into categories Decide where to put items such as images and sound files Use the same structure for local and remote sites Setting up a Dreamweaver site A Dreamweaver site consists of as many as three parts, depending on your environment and the type of website you are developing: Local folder is your working directory. Dreamweaver refers to this folder as your local site. Remote folder is where you store your files, depending on your environment, for testing, production, collaboration, or so on. Dreamweaver refers to this folder as your remote site Folder for dynamic pages is the folder where Dreamweaver processes dynamic pages. To set up a Dreamweaver site: 1. Select Site > New Site. The Site Definition dialog box appears. 2. Click the Basic tab to use the Site Definition Wizard, or click the Advanced tab to use the Advanced settings. Note: Users who are new to Dreamweaver are encouraged to use the Site Definition Wizard; experienced Dreamweaver users might prefer to use the Advanced settings.

Setting Up Local Folder

Setting Up Testing Server

Connecting to database To create a database connection with a MySQL Connection: 1. Click the plus (+) button on the Application > Databases panel and select MySQL Connection from the pop-up menu. 2. Enter values as shown below except value for the database. 3. Click button Select and choose database student. 4. Click button OK to finish the configuration. The MySQL Connection dialog box appears.

*You can click button Test to check the connection successful or not The result of the successful connection is shown below. Collapse student database and make sure the tables name exist.

Creating Interactive Forms Client-side role of forms Forms support the client side of the client-server relationship. When a visitor enters information into a form displayed in a web browser (the client) and clicks the submit button, the information is sent to the server where a server-side script or application processes it. Common server-side technologies used for processing form data include Macromedia ColdFusion, Microsoft Active Server Pages (ASP), and PHP. The server responds by sending requested information back to the user (or client), or performing some action based on the forms contents.

Forms allow you to interact with or gather information from visitors to a website. Forms collect information from the user and submit this information to the server for processing. Forms can contain various objects that enable user interaction. These form objects include text fields, list boxes, check boxes, and radio buttons. The form tag includes parameters that let you specify a path to the server-side script or application that will process the form data, and which HTTP method to use when transmitting data from the browser to the server. About form objects In Dreamweaver, form input types are called form objects. You can insert form objects by choosing Insert > Form Objects, or by accessing the form objects from the Forms panel of the Insert bar shown below.

The Forms bar provides the following buttons:

Form

Inserts a form in the document. Dreamweaver inserts opening and closing form tags in the HTML source code. Any additional form objects, such as text fields, buttons, and so on must be inserted between the form tags for the data to be processed correctly by all browsers.

*In the Method pop-up menu, choose the method that will transmit the form data to the server. The form Methods are: POST GET Embeds the form data in the HTTP request. Appends the value to the URL requesting the page.

Default Uses the browsers default setting to send the form data to the server. Typically the default is the GET method. Do not use the GET method to send long forms. URLs are limited to 8,192 characters. If the amount of data sent is too large, data will be truncated, leading to unexpected or failed processing results. Also, do not use GET method when sending confidential user names and password, credit card numbers, or other confidential information. GET is not a secure method for passing information.

Text Field & Text Area

Inserts a text field in a form. Text fields accept any type of alphanumeric entries. The entered text can be displayed as a single line, as multiple lines, or as bullets or asterisks (for password protection). Single-line text fields typically provide a single word or short phrase response, such as a name, or an address. Multiple-line text fields provide the visitor with a larger area in which to enter a response. You can specify the maximum number of lines the visitor can enter, and the

character width of the object. If text is entered that exceeds these settings, the field will scroll, following the setting specified in the wrap attribute. Password fields are a special type of text field. When a user types in a password field, the entered text is replaced by asterisks or bullets to obscure the text, and protect the information from being viewed.

Hidden Field

Inserts a field in the document in which user data can be stored. Hidden fields let you store information entered by a user, such as a name, e-mail address, or purchase preference, and then use that data when the user next visits the site.

Check Box

Inserts a check box in a form. Check boxes allow multiple responses in a single group of options, a user can select as many options as apply.

Radio Button

Inserts a radio button in a form. Radio buttons represent exclusive choices. Selecting a button within a group deselects all others in the group. For example a user can select Yes or No.

Radio Group

Inserts a collection of radio buttons which share the same name. Understanding checkboxes and radio buttons Check boxes toggle each individual response off and on. Thus, a user can select more than one option from a checkbox group. The example below illustrates this by showing three checkbox items selected: Surfing, Mountain Biking, and Rafting.

Radio buttons work as a group and provide mutually exclusive selection values. A user can select only one option within a radio button group. In the example below, Rafting is the currently selected option. If the user were to click Surfing, the Rafting button would be automatically deselected.

List/Menus

Allows you to create user choices in a list. The List option displays the option values in a scrolling list and allows users to select multiple options in the list. The Menu option displays the option values in a pop-up menu and allows users to select only a single choice.

Jump Menu

Inserts a navigational list or pop-up menu. Jump menus let you insert a menu in which each option links to a document or file

Image Field

Allows you to insert an image in a form. Image fields can be used in place of Submit buttons to make graphical buttons.

File Field

Inserts a blank text field and a Browse button in a document. File fields let users browse to files on their hard disks and upload the files as form data.

Button

Inserts a text button within a form. Buttons perform tasks when clicked, such as submitting or resetting forms. You can add a custom name or label to a button, or use one of the predefined Submit or Reset labels.

Exercise : Create a Form as shown below (textfield, textarea, radio button, list/menu, buttons and table) save as student_reg.php

Make sure the name for each form objects are same with field name. You can change the name by selecting the form object and go to Properties Panel.

Text Field: Name

Create new file name congra_saving.php. The content of the file is shown below.

Server Behaviors

Insert Record

You can use a Record Insertion Form application object to create a form which links to the fields of a database. The application object lets you select which fields to include in the form, label fields, and select the type of form objects to insert. When a user enters data in the form fields and clicks the submit button, a new record is inserted in a database. You can also set a page to open after a record has successfully been submitted so the submitter knows the database was updated.

1. 2. 3. 4. 5. 6.

Choose Connection. Choose Insert table. Make sure in Columns all values are assigned to field name. Click button Browse and choose file congra_saving.php. Click button OK. In Application > Server Behaviors the Insert Behavior will be added.

To make any changes, just click the behavior and you will get Insert Record dialog box again.

Validate Form
The Validate Form action checks the contents of specified text fields to ensure that the user has entered the correct type of data. Attach this action to individual text fields with the onBlur event to validate the fields as the user is filling out the form, or attach it to the form with the onSubmit event to evaluate several text fields at once when the user clicks the Submit button. Attaching this action to a form prevents the form from being submitted to the server if any of the specified text fields contains invalid data.

To use the Validate Form action in registration.php 1. Do one of the following: o To validate individual fields as the user fills out the form, select a text field and select Window > Behaviors. o To validate multiple fields when the user submits the form, click the <form> tag in the tag selector in the bottom left corner of the Document window and select Window > Behaviors. 2. Select Validate Form from the Actions pop-up menu. 3. Do one of the following: o If you are validating individual fields, select the same field that you have selected in the Document window from the Named Fields list. o If you are validating multiple fields, select a text field from the Named Fields list. 4. Select the Required option if the field must contain some data. 5. Select from one of the following Accept options: Use Anything if the field is required but need not contain any particular kind of data. (If the Required option is not selected, the Anything option is meaningless-that is, it is the same as if the Validate Form action were not attached to the field.) Use E-mail address to check that the field contains an @ symbol. Use Number to check that the field contains only numerals. Use Number From to check that the field contains a number in a specific range. 6. If you are validating multiple fields, repeat steps 3 and 4 for any additional fields that you want to validate. 7. Click OK. If you are validating multiple fields when the user submits the form, the onSubmit event automatically appears in the Events pop-up menu. 8. If you are validating individual fields, check that the default event is onBlur or onChange. If it isnt, select onBlur or onChange from the pop-up menu. Both of these events trigger the Validate Form action when the user moves away from the field. The difference between them is that onBlur occurs whether or not the user has typed in the field, and onChange occurs only if the user changed the contents of the field. The onBlur event is preferred when you have specified that the field is required.

Named Fields std_name std_id std_phone_h std_phone_hp std_address

Value Required Required Not Required Not Required Required

Accept Anything Number

Anything

*The std_gender and std_origin do not show because both have the default values. After click button OK the Validate Form is added in Behaviors as shown below with event onSubmit.

Tips: The validate form behavior also can be applied to page Log In, Insert, Update and Search.

Recordset (Query)
Now youll create a recordset to select the data you want to display. A recordset is a subset of information extracted from a database by a database query. A database query consists of search criteria, which defines whats included in the recordset. You then use the information extracted as a source of content for your dynamic pages. To open recordset: Click recordset in Server Behaviors and the below recordset will appear.

Enter the name (rsstudent) Click Test to test the recordset

Click OK to close the Test SQL Statement window. Click OK to close the Recordset or DataSet dialog box.

The recordset appears in the Bindings panel.

Create a page as shown below: 1. 2. 3. 4. 5. Insert table with 2 rows and 3 columns. Drag and drop the appopriate fields as shown Highlight the second row and choose Repeat Region in Server Behavior panel Highlight the table and choose Show Region if Recordset Not Empty Highlight No Student Record Available and choose Show Region if Recordset is Empty 6. Name the page as student_list.php

Repeating Region
Lets you repeat a region but doesnt include an editable region. However, you can insert an editable region in a repeating region to make it editable. After you have added a recordset to a page, and have created a navigation bar, you must apply individual server behaviors to each navigation element. For example, a typical recordset navigation bar contains representations of the following links matched to the appropriate behavior:

Recordset Paging
Navigation link Go to first page Go to the previous page Go to the next page Go to the last page Server behavior Move to first page Move to previous page Move to next page Move to last page

To assign server behaviors to record navigation links: 1. In Design view, select the text string or image on the page you want to use as a record navigation link. 2. Open the Server Behaviors panel (Window > Server Behaviors) and click the plus (+) button. 3. Choose Recordset Paging from the pop-up menu, then select a server behavior appropriate to that link from the listed server behaviors. Note that if the recordset contains a large number of records, the Move to Last Record server behavior can take a long time to run when the user clicks the link. 4. In the Recordset pop-up menu, select the recordset containing the records. 5. Click OK.

Show Region
The Show Region server behaviors are:

Show If Recordset Is Empty Show If Recordset Is Not Empty Show If First Page Show If Not First Page Show If Last Page

Show If not Last Page

To show a region only when its needed: 1. In Design view, select the region on the page to show or hide. 2. In the Server Behaviors panel (Window > Server Behaviors), click the plus (+) button. 3. Choose Show Region from the pop-up menu, then choose one of the listed server behaviors. 4. Click OK.

Filtering Record Set (Query)

# Update and Delete will be used when to update and delete the informations of the student To link page student_list and student_detail.php do as following: 1. Highlight {rsStudent.std_name} and right click mouse and choose Make Link. The dialog box as shown as below.

2. Choose student_detail.php and click Paratemters button.

3. Type std_id in column Name. Click button Dynamic under Value and select std_id.

4. Click OK.

Update Page
Before update please make sure you have done this: 1. Create cong_update.htm page. 2. Create Form as shown below. Save as student_update.asp

3. Create recordset with id as a filter.

4. Select Update Record in Server Behavior Panel.

The Record Update Form dialog box appears.

5. Complete the dialog box. 6. Click OK.

Delete Page
Before delete please make sure you have done this: 1. Create cong_delete.htm page. 2. Create Form as shown below. Save as student_delete.asp

3. Create recordset with id as a filter.

4. Open the page in Design view, then choose Insert > Application Objects > Delete Record Form. The Delete Record Form dialog box appears.

5. Complete the dialog box. 6. Click OK.

Log In User
Before log in please make sure you have done this: 1. Create menu.php page. 2. Create sorry.php page. 3. Create Form as shown below. Save as index.php

4. Open the page in Design view, then choose Server Behavior > Application Objects > User Authentication > Log In User. The Log In User Form dialog box appears.

5. Complete the dialog box. 6. Click OK.

APPENDIX
MySQL 1: Reserved Words ADD ANALYZE ASC BDB BETWEEN BLOB CALL CHANGE CHECK COLUMNS CONSTRAINT CROSS CURRENT_TIMESTAMP DATABASES DAY_MINUTE DECIMAL DELAYED DESCRIBE DISTINCTROW DROP ENCLOSED EXIT FETCH FOR FOUND FULLTEXT HAVING HOUR_MINUTE IGNORE INFILE INOUT INT INTO ITERATE KEYS LEAVE LIMIT LOCALTIME LONG LOOP ALL AND ASENSITIVE BEFORE BIGINT BOTH CASCADE CHAR COLLATE CONDITION CONTINUE CURRENT_DATE CURSOR DAY_HOUR DAY_SECOND DECLARE DELETE DETERMINISTIC DIV ELSE ESCAPED EXPLAIN FIELDS FORCE FRAC_SECOND GRANT HIGH_PRIORITY HOUR_SECOND IN INNER INSENSITIVE INTEGER IO_THREAD JOIN KILL LEFT LINES LOCALTIMESTAMP LONGBLOB LOW_PRIORITY ALTER AS AUTO_INCREMENT BERKELEYDB BINARY BY CASE CHARACTER COLUMN CONNECTION CREATE CURRENT_TIME DATABASE DAY_MICROSECOND DEC DEFAULT DESC DISTINCT DOUBLE ELSEIF EXISTS FALSE FLOAT FOREIGN FROM GROUP HOUR_MICROSECOND IF INDEX INNODB INSERT INTERVAL IS KEY LEADING LIKE LOAD LOCK LONGTEXT MASTER_SERVER_ID

MATCH MEDIUMTEXT MINUTE_SECOND NOT NUMERIC OPTION ORDER OUTFILE PRIVILEGES READ REGEXP REPLACE RETURN RLIKE SENSITIVE SHOW SONAME SQL SQLWARNING SQL_SMALL_RESULT SQL_TSI_HOUR SQL_TSI_QUARTER SQL_TSI_YEAR STRAIGHT_JOIN TABLES TIMESTAMPADD TINYINT TRAILING UNION UNSIGNED USE UTC_DATE VALUES VARCHARACTER WHERE WRITE ZEROFILL

MEDIUMBLOB MIDDLEINT MOD NO_WRITE_TO_BINLOG ON OPTIONALLY OUT PRECISION PROCEDURE REAL RENAME REQUIRE REVOKE SECOND_MICROSECOND SEPARATOR SMALLINT SPATIAL SQLEXCEPTION SQL_BIG_RESULT SQL_TSI_DAY SQL_TSI_MINUTE SQL_TSI_SECOND SSL STRIPED TERMINATED TIMESTAMPDIFF TINYTEXT TRUE UNIQUE UPDATE USER_RESOURCES UTC_TIME VARBINARY VARYING WHILE XOR

MEDIUMINT MINUTE_MICROSECOND NATURAL NULL OPTIMIZE OR OUTER PRIMARY PURGE REFERENCES REPEAT RESTRICT RIGHT SELECT SET SOME SPECIFIC SQLSTATE SQL_CALC_FOUND_ROWS SQL_TSI_FRAC_SECOND SQL_TSI_MONTH SQL_TSI_WEEK STARTING TABLE THEN TINYBLOB TO UNDO UNLOCK USAGE USING UTC_TIMESTAMP VARCHAR WHEN WITH YEAR_MONTH

Anda mungkin juga menyukai