To make progress on Project 3 and to understand...
Remember that you must...
Use WinSCP to connect to our remote server.
Details about your specific server, userid and password were emailed to you. Here is the general information:
ftp.sienasellbacks.com
or ftp.breimer.net
userid@sienasellbacks.com
or userid@breimer.net
Be sure to replace userid
with your actual Siena userid; But, do not add @siena.edu
To share PHP code, I have uploaded the scripts as .txt files. After you download these files be sure to rename them so that the file extension is .php
project3
folder, rename your functions.php
to functions_old.php
project3
folderproject3
folderfunctions.php
in Bracketsfunctions_database.php
which allows us to better organize our functions based on their rolesselect_menu
function will return one of the three menus based on two session variables:
$_SESSION['admin']
is set to true
if an administrator is logged in or it is null/false
$_SESSION['uid']
is set to the uid
of the logged in user or it is null/false
select_menu
is called each time a page is generated, which allows the main menu
to change depending on which kind of user is logged inKey Task: Create files for each of the PHP scripts in the three menus. Note that logout.php
appears twice and that show_table_data.php
and show_table_columns.php
are each one script, but are linked
twice with different table_names.
functions_database.php
in Bracketsdb_connect
function to connect the correct database
breimern
corresponds to breimer.netsienasel
corresponds to sienasellbacks.comrun_query
which properly connects to the database, uses the die
function to
display an error message if the query fails, and properly closes the database connection. Using this function will
help you avoid errors and will help you debug.We are going to rebuild our tables to clear out all the test data and to be sure everyone has the correct columns.
Remember to always replace userid
with your own userid.
Thus, you will create your own tables. Otherwise, many students will be overwriting the same tables.
project3
folderhttp://www.breimer.net/userid/projects/project3/drop_table.php?table_name=userid_courses
orhttp://www.sienasellbacks.com/userid/projects/project3/drop_table.php?table_name=userid_courses
orproject3
folderproject3
folderproject3
folderproject3
folderThe user profiles are meant to be public. New visitors can do three things: join, login or view the users' profiles.
Implement the show_users.php
script as follows:
make_basic_page
function.$content
string and pass it to the make_basic_page
function.
The page name should be "Users" as this is the name of the menu item for this particular page.
run_query
function to get the result
of the following query:SELECT uid, first, last, major, col FROM userid_users
fetch_assoc
method on the result
pointer to get all the rowsuser_profile.php?uid=x
where x
is the uid
of a user
The user profiles should include all the information in the users table.
The user_profile.php
script takes the uid
as a parameter:
Example: user_profile.php?uid=3
make_basic_page
function.uid
from the URL, i.e., $uid = $_GET['uid']
run_query
function get the result
of the following query:SELECT * FROM userid_users WHERE uid='$uid'
fetch_assoc
method on the result
pointer to get the single row return by the query.
user_data
user_data
associative array can be used to slice in any user specific data$content = '<h1>'.$user_data['first'].' '.$user_data['last'].'</h1>';
make_card
to put data inside of a card.$content .= make_card("Biography",$user_data['bio']);
The login will create and process a basic form. It fetches a user's stored password (stored in the database) and compares it to the password submitted in the form. It will set a session variable with the user's id (uid) that the server will remember, so that when a logged in user visits other pages, we can generate content for that specific user.
project3
folder"pwd"
you can fetch it using $_POST['pwd]
submitted_email
and submitted_pwd
SELECT uid, pwd FROM userid_users WHERE email='$submitted_email'
fetch_assoc
on the query results pointer$row
, you can get the stored uid as follows:$stored_uid = $row['uid']
stored_pwd
session_start()
$_SESSION['uid'] = $stored_uid;
$_SESSION['uid']
if the submitted_pwd
matches the stored_pwd
None. To get credit for lab you must work productively for the 2 hour period.
While it is OK to help other students with concepts and general trouble-shooting, you should not share code. It is expected that each individual project will be unique.