Forum Moderators: coopster
The following is my codes.
form.htm
<form name="form1" method="post" action="details.php">
<p>
<label>User name
<input type="text" name="name">
</label>
</p>
<p>
<label>Password
<input type="password" name="passwd">
</label>
</p>
<p>
<label></label>
</p>
<p align="center">
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
details.php
<?php
// listing script
// connect to the server
mysql_connect( 'localhost', 'user', 'pass4' )
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( 'db' )
or die( "Error! Could not select the database: " . mysql_error() );
$user_name = $_POST["name"];
$passwd = $_POST["passwd"];
//$topic1 = $_POST["sub1"];
$query = "SELECT * FROM logpage ";// WHERE user = "$user_name" AND password = "$passwd";
$result = mysql_query($query);
$num_rows = mysql_numrows($result);
for($i =1; $i<=$num_rows; $i++){
$name = mysql_result($result, $i, "user");
$password = mysql_result($result, $i, "password");
if($user_name == $name && $passwd == $password){
$flag = "old";
break;
}
}
if($flag!= "old"){
//include("evaluation.php");
$query = "INSERT INTO logpage (id, user, password) VALUES (NULL,'$user_name', '$passwd')";
}
else{
//include("evaluation.php");
$query = "UPDATE `logpage` SET `user`='$user_name', `password`='$passwd'
WHERE `id`='$id'";
}
$query = "SELECT * FROM `logpage` WHERE `user` = '$user_name' AND `password` = '$passwd'";
$results = mysql_query($query);
if( $results && $contact = mysql_fetch_object( $results ))
{
$id = $contact -> id;
$user = $contact -> user;
$pass = $contact -> password;
//echo "this is a test.";
echo( "$user, $pass, $id<br>" );
include("evl_form.php");
?>
<?php
//}
}
else
{
die( "Trouble getting contacts from database: " . mysql_error() );
} //
?>
evl_form.php
<form name="form1" method="post" action="thanks.php">
<label> Subject 1
<input name="sub1" type="radio" value="1">
1</label>
<label><input name="sub1" type="radio" value="2">
2</label>
<p>
<label></label>
</p>
<label> Subject 2
<input name="sub2" type="radio" value="1">
1</label>
<label>
<input name="sub2" type="radio" value="2">
2</label>
<label>
<input type="hidden" name="user" value = "<?php echo $user_name?>">
<input type="hidden" name="id" value = "<?php echo $id?>">
</label>
<p align="center">
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
thanks.php
<?php
echo "THank you for your time.<br>";
$id= $_POST['id'];
$user = $_POST['user'];
$sub1 = $_POST["sub1"];
mysql_connect( 'localhost', 'user', pass4' )
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( 'db' )
or die( "Error! Could not select the database: " . mysql_error() );
$query = "SELECT * FROM eval_table ";// WHERE user = "$user_name" AND password = "$passwd";
$result = mysql_query($query);
$num_rows = mysql_numrows($result);
for($i =1; $i<=$num_rows; $i++){
$name = mysql_result($result, $i, "user");
if($user_name == $name ){
$flag = "old";
break;
}
}
if($flag!= "old"){
//include("evaluation.php");
$query = "INSERT INTO eval_table (id, user, topic1) VALUES (NULL,'$user', '$sub1')";
}
else{
//include("evaluation.php");
$query = "UPDATE `eval_table` SET `topic1`='$sub1'
WHERE `user`='$user'";
}
$results = mysql_query( $query );
if( $results )
{
echo( "Successfully saved the entry.<br>" );
}
else
{
die( "Trouble saving information to the database: " . mysql_error() );
}
$query = "SELECT * FROM `eval_table` WHERE `user` = '$user'";
$results = mysql_query( $query );
// print out the results
if( $results )
{
if( $contact = mysql_fetch_object( $results ) )
{
// print out the info
$id = $contact -> id;
$user = $contact -> user;
$password = $contact -> password;
$topic1 = $contact -> topic1;
echo "For user ", $user, " the reply is ",$topic1, "<br>";
}
}
else
{
die( "Trouble getting contacts from database: " . mysql_error() );
}
?>
Without writing it all out for you, here are some things you will need to do (you already have some of them, but I will go through the list):
1. Store the users/passwords, other info that you will need for determining current users, etc. -- table 1
2. Store the form question -- table 2
3. Store the results of the form -- either A). table 3 stored answers with username (or id number) in an extra col for association B). create a table 'username' for each user and store the results there.
4. When someone logs in check the username and password.
5. Select the previous set of questions (If a more recent set is posted.)
6. Select the corresponding set of answers from table 3 or username table.
7. Show the results.
5 & 6 Should be easy to select if you use a 'username' table, because the id of the question table and the answers in the username table will be the same -- If someone has not completed an eval, they will not have the most recent id, so they should be prompted to complete that eval. EG if there are 3 sets of questions and only 2 sets of answers for any student you will know they should be completing set 3 of the questions and you need to show set 2 as the previous, but if there is a 3 for each, they have answered all sets and set 3 answers should be shown.
Hope this gives you some ideas.
Justin
Thanks again. I really appreciate you help.
1. It would be very easy to keep track of the evaluations and use them again once they are entered EG next semester.
2. It would be easy for the instructor to add, edit, delete questions from the evaluations with a simple web-based form.
3. It would be easy to find the next evaluation in the set that a person should complete, if there are 15 total evaluations and a person has rows 1 & 2 in their table I could automate showing eval #3 and results from eval #2 very simply.
-- Basically, it is the easiest way to accomplish what you are looking for after the initial set-up.
can I just show the user the evaluation form and when he/she finishes the evaluaction for topic eg. 1 and after submit it I store the result in table3.
Yes, there are a number of ways to do this.
I would #1 select the max id from the USERNAME table. This would tell me what the last eval they completed was -- If there are two rows, I know the eval they need to complete is number 3.
Something like:
"SELECT * FROM ".$username." ORDER BY id LIMIT 1";
Then I would display the results from the USERNAME table, so in the example above, the user would see the results of the second evaluation on the page. Then I would put a link to the next eval to be completed. (Something like "<a href=\"/form.php?eval=".($selected['id']+1)."\">Complete the Next Eval</a>";
This would add one to the row number of the results I selected from the users table, which would give me the row id of the next eval in the form table.
Then I could select the next set of eval questions with something like this:
"SELECT * FROM froms WHERE id=".$eval."";
You could also go in the opposite order and select the last row in the user table, then immediately select the next eval to be completed and display it, with a link to the previous eval...
Hope this helps.
Justin
Added: I mean pull the questions from the table, and display them into a form.