Introduction
This assignment is to use PHP to make your login script connect to a database.
I have set up a database on babbage for each of you. The PHP statement to connect to your database takes the following form:
$conn = pg_connect( "user=$user host=$host password=$password dbname=$user" );
Your code must initialize the $user, $host, and $password variables before exectuting this statement. The user name and database name are the same: your lab account name without the numbers; your password is just the numbers from your course account name, and the host is babbage.cs.qc.cuny.edu.
If the connection is made successfully, $conn will be set to a small integer representing a “resource” (which works like true in if statements). If the connection attempt fails, the value of $conn will be null (which works like false in if statements).
The databases can only be accessed from computers on campus.
The Assignment
If you have not done so already, update your login.php script so that it displays a message containing the user’s email address, based on the value of the corresponding field on the form. Take out all alert() statements from your JavaScript code.
Update your login.php script so that it displays a message indicating whether it is able to connect to your database successfully or not. Test it using the wrong password (or user name or database name or host name) to be sure it handles failures as well as successes.
Submit The Assignment
When your assignment is working, log out and be sure your profile is copied back to the server. Send me an email message telling me that you have completed the assignment, and I will get a copy of it from your account on Oak for testing. If your roaming profile does not work, mention that in your email, and I will copy your My Website directory from your home directory instead of your profile directory on Oak.
- Be sure to put your name in your email message!
- The Subject line must be CS-90.3 Assignment 5 to avoid my spam filters.
- Send your email to either Christopher.VickeryATqc.cuny.edu or vickeryATbabbage.cs.qc.cuny.edu — but not to both.
- See the course syllabus for grading and late homework policies.