![]() |
![]() Spring Semester 2005 Joint work with former A348 student Aaron Bond. |
This happens on burrow, but simulates the environment on value web.
Create two tables, one for users, the other one for transactions:
Populate one of the tables:create table users_0226_draft ( username varchar(32) not null primary key, password varchar(20) not null, lastName varchar(20) not null, firstName varchar(20) not null ) create table transactions_0226_draft ( username varchar(32) not null, timestamp timestamp, amount double not null, primary key (username, timestamp) )
Check this on burrowww, it's what you see.insert into users_0226_draft values ( 'lbird@pacers.com', 'dribl', 'Bird', 'Larry' ), ('mjordan@bulls.com', 'bulls', 'Jordan', 'Michael'), ( 'tkukoc@bulls.com', 'abc', 'Kukoc', 'Toni' ), ('rartest@pacers.com', 'fight', 'Artest', 'Ron' ), ('rmiller@pacers.com', 'reggie', 'Miller', 'Reggie' )
Then write three scripts (note the extra folder):
The first script just displays the login screen:burrowww.cs.indiana.edu% ls -ld * drwxr-xr-x 2 dgerman faculty 512 Feb 26 21:21 sessions -rw-r--r-- 1 dgerman faculty 397 Feb 26 20:23 one.php -rw-r--r-- 1 dgerman faculty 892 Feb 26 21:13 three.php -rw-r--r-- 1 dgerman faculty 1055 Feb 26 21:01 two.php burrowww.cs.indiana.edu%
<? session_save_path('/nfs/paca/san/r1a0l1/dgerman/apache/apache_1.3.26/htdocs/0226_draft/sessions');
session_start();
?>
<form method="GET" action="./two.php">
<table>
<tr> <td> Username
<td> <input type="text" name="uname">
<tr> <td> Password <td> <input type="password"
name="pword">
</table>
<p> When ready please press <input type="submit"
value="Proceed">
</form>
The second one checks the username and the password:
<? session_save_path('/nfs/paca/san/r1a0l1/dgerman/apache/apache_1.3.26/htdocs/0226_draft/sessions');
session_start();
$result = mysql_connect("localhost", "a348", "a348AG");
if ($result) {
if (mysql_select_db("a348")) {
echo "I can select the database. <p>";
$query = "select username, password from users_0226_draft where username =
'$uname' and password = '$pword'";
$result = @mysql_query($query);
if ($row = mysql_fetch_row($result)) {
echo "(" . $row[0] . ", " . $row[1] . ")";
session_register("username");
$username = $row[0];
?>
<form method="GET" action="./three.php">
Type here the amount: <input type="text" name="pledge"> <p>
Please press <input type="submit"
value="Proceed"> when ready.
</form>
<?
} else {
echo "I am sorry, can't find the record. <p>";
}
} else {
echo "I can connect but I can't select the database. <p>";
}
} else {
echo "I cannot connect. <p>";
}
?>
The third one stores the new pledge (notice you can't reload):
<? session_save_path('/nfs/paca/san/r1a0l1/dgerman/apache/apache_1.3.26/htdocs/0226_draft/sessions');
session_start();
$result = mysql_connect("localhost", "a348", "a348AG");
if ($result) {
if (mysql_select_db("a348")) {
echo "I can select the database. <p>";
$query = "insert into transactions_0226_draft values ('$username', null, $pledge)";
// echo $query;
if (session_is_registered("username")) {
$result = @mysql_query($query);
if (! $result) {
echo "I am sorry, I can't do
that.";
} else {
session_destroy();
echo "Good, you're done.";
}
} else {
echo "There's no point reloading.";
}
} else {
echo "I can connect but I can't select the database. <p>";
}
} else {
echo "I cannot connect. <p>";
}
?>
Now these scripts need to be tightened up (POST, MD5, admin scripts). I will have an update ready sometime on Sunday. Here's the link to the program.