Prototype 6: Assignment02: Registration form+ server-side logic anduser-defined function.

Paper copydue next week before end of class (the day depends on your section); heading: Prototype 6: your fullname,

stapled, no hand-writing , neat! Use two-sided page(s) if possible. Points taken off if not neat/professional looking.

Examples/Notes:

Study related homework questions and additional topics at:

Objectives: SQL insert & update, more complex script logic, user-defined functions to simplify implementation

Refer to: especially2, 4, 7-9.

Videos: PHP user-defined functions 6C:5:00-end; Javascript 5D, 5D1; additional Javascript discussion/example: 6B

Hashing functions and encryption: 6D, 6E, Video 3B1: SQL Injection and mysql_real_escape_string.

1. Define HTML form with inputs for REGISTERED (except script/system defined registration_datetime); action=register.php. Can temporarily ignore layout issues.

2. Define a new functionREGISTERED_count($username)which returns the number of times $username is in REGISTERED. Place function definition in myfunctions.php file. The function definition is like: REGISTERED_count($username) { } with body:{$s = "select * from REGISTERED where username = '$username' "; $t = mysql_query ($s); return mysql_num_rows($t)}

BEWARE: as it stands this function omits an important consideration: it does not screen out new usernames that have a repeated email address (which are required also to be unique). A repeat emailentry will be rejected if you try to add /insert a new user to the REGISTERED table with an existing email address. Thus, REGISTERED_count should actually have two parameters and a slightly different where condition that recognizes duplications in either the username or the email address. You don't need that for proto-p6 but it is needed for Assignment02. The function would be REGISTERED_count ($username, $email).

3. Defineregister.php(a)connect to database and include ("myfunctions.php file ") to be able to invoke the new function. (b) First test by invoking the function with usernames from the form,both for names in, and not in, REGISTERED. Output the count returned by the functionin each case. This establishes there are no syntax errors and the function behaves as intended.

4. Complete implementation of register.php withuser-defined function described on SLIDES 2,4 7-9of PPTabove (with data sanitizing mentioned there). REGISTERED_count functionsafeguards against scripttrying to insert an already existing username or email in REGISTERED, butlets it accept/insert form data in REGISTERED table if the usernameand email are new.

6Snapshots

1. Rendered (that is browser) view of HTML registration form: register.html.

2. HTML code for register.html.

3. Display (readable copy) PHP code for myfunctions.php with code for.REGISTERED_count function.

4. Display (readable copy) PHP code for register.php with just basic SQL insert process and using the

REGISTERED_count function described in (step 4) above.

5. Browser output from register.php when input username already exists.

6. Browser output from register.php when input username is new and user is registered successfully.

1. Rendered browser view of basic HTML form. All elements must be present and labeled.

Prototype layout should be roughly as shown [or improved one of your own design.] But the primary focus of this prototype is the PHP server-side processing.

2. HTML code for register.html.

Snapshot of Notepad++ or other clear view of HTML code forregister.html

3. PHP code for myfunctions.php.

Snapshot of Notepad++ or other clear view of PHP code for

REGISTERED_count ($username) - preferably REGISTERED_count ($username, $email)

4. PHP code for register.php with insert process using REGISTERED_count function as described in step (4) on previous page.

Snapshot of Notepad++ or other clear view of PHP code for

register.php as described on slide 4, 7, 8 of PowerPoint for assignment02

5. Browser outputfrom register.php if input username already exists.

Snapshot of browser view of output from register.php for a test usernamethat already exists: It

should have a message indicating the username is already in the database.

6. Browser outputfrom register.php when input username is new and user is registered successfully

Snapshot of browser view of output from register.php for new username.

It should echo input data and indicate user is inserted into REGISTERED TABLE.

proto-p5.docxPage 1