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
form
, please be sure that
method="post"
and action="insert_user.php"
insert_user.php
, so the script can generate the form and also process the form.method="post"
, the names and values of these form elements
will be stored in the $_POST
variable.
Since there are 11 form elements that could me mispelled
(email, pwd, first, last, col, major, fyear, gyear, cred, bio, and grad), it would be good to create this string and check each value via a loop.
$_POST
array ($_POST as $field=>$value
)$value != ''
then set valid to true and concatenate $field,
and '$value',
to seperate strings ($fields
and $values
$fields
and $values
stringsINSERT INTO $table_name ($fields) VALUES ($values)
where $table_name
is your user table name and $fields
and $values
are the string you created via your loop.
input
element has an optional value
attribute that can be set to the previously posted value:<input name="email" value="'.$_POST['email'].'">
logout.php
script is an example of a script that does work on the server, but never produces any output.
session_destroy()
, which deletes all the session variables and sends an HTTP response to the web browser to delete the corresponding cookie.
session_start()
will actually restore a previously started session, so PHP knows which
session to destroy.
header("Location: login.php")
can be used to redirect to the login, a most common mistake is to have a typo in "Location:". The captial L and colon matter.
To make each redirect less error prone, I defined a redirect function that can be used as follows: redirect("login.php")
UPDATE users SET email='new value',pwd='new value',first='new value',last='new value',col='new value',major='new value ',fyear='new value',gyear='new value',cred='new value',bio='new value',grad='new value' WHERE uid='current logged in user'
uid
of the current logged in user is stored in the $_SESSION['uid']
variable.update_user.php
, be sure to change the action to "update_user.php"insert_user
inserted previously submitted values into the form elements so that you did not need to retype them.
<input name="email" value="'.$_POST['email'].'">
.update_user
can fetch all the stored values with the following query:$result = run_query("SELECT * FROM $table_name WHERE uid='current logged in user'");
$row = $result->fetch_assoc();
<input name="pwd" value="'.$row['pwd'].'">
INSERT INTO courses (sub,num,title,descr,year,sem, uid) VALUES ('CSIS','499','Independent Study','Advanced Robotics','2018','Fall', 1)
1
is the uid
of the current logged in user, which you can get from the session, i.e., $_SESSION['uid']
show_table
that you can use to show all the courses. You can creat a simple script that calls this function and passes the name of your courses table.
show_table
that you can copy and modify to display courses for a specific user or for a specific year and semester.
SELECT sub, num, descr, title FROM $table_name WHERE year='$year' AND sem='$sem' AND uid='$uid'
$next_year = $year + 1;
SELECT sub, num, descr, title FROM $table_name WHERE (year='$year' AND sem='Fall' OR year='$next_year' AND sem='Spring') AND uid='$uid'
cid
instead of the uid
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.