CIS 430 Assignment – PHP, ASP, ADO, forms, & cookies


Create a simple contact form using PHP.  The form should include four fields: 

The form should resemble the following.  Be sure the labels and form fields are aligned.

After the user fills out the form and hits the Submit Query button, the form data should be stored in a MySQL database using PHP code. 

MySQL details:

Database table details (same in both database tables):

Take a look at the additional notes link for PHP, and look particularly at the source code link for the MySQL example.  Notice that each of the commands begins with mysqli_, such as mysqli_connect.  You need that syntax to get your assignments to work correctly.

The page should also set a cookie on the user's machine called "namecookie" with the value equal to the user id that was just entered and an expiration in ten hours.  (Note: replace name with your last name, such as Smithcookie.)  To get the user id you should be able to do a Select Max (userID) AS LastID from assnseven;.  If you do this prior to inserting the record, you will have to increment the LastID by 1 using the ++ prefix operator.

You can force your PHP page to automatically open the ASP page by including a refresh meta tag in the <head></head> section of the PHP page.  The syntax is

<META http-equiv="refresh" content="5;URL=http://nextPage.aspx">

See tip at bottom

The next step requires that you write an ASP.Net program that uses ADO to connect to the database and extracts the data from the database.  You will have to read the userID value from the cookie and use it in the where clause to read the correct data item from the database table.  The program should then use that data to build a web confirmation page that echoes the data that was entered by the user.  (Yes, you could get the data directly from the form to create the page, but you are required to use ASP.NET.) Recall Assignment 4 for an example.

 

In order to set a cookie in PHP and then read it in ASP.Net, you must include a fourth parameter in the setcookie call. The PHP syntax looks like this

setcookie(<name>, <value>, <expiration>, "/");

If you don't include that fourth argument, then you can search for twelve plus hours like I did trying to get it to work!

Run the sample script for examples.


Helpful tips from students:

Be sure you refer to your ASP page using the URL http://classweb.cob.isu.edu/cis430/... rather than http://cob.isu.edu/cis430/... (since that isn't our URL)

Also, one student noted that he HAD to view his code in Visual Studio browser before it would work (since that is the step that compiles it).


This assignment may be weighted more heavily than the others, since it covers multiple topics.