
October 1st, 2004, 12:49 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 16
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Forms
I badly need help. I have these codes. I'm doing a statuslog form. Before the user could go the form he/she has to log in.
PHP Code:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> <html> <head> </head> <body> <form action="validationtest.php" method=post> <table align=center style="font-family:arial; font-size:12; border:1 solid #000000;"> <tr><td colspan=2 align=center bgcolor=#123dd4>LOGIN</td></tr> <tr><td align=right>Username: </td><td><input type=text name=username size=15></td></tr> <tr><td align=right>Password: </td><td><input type=password name=password size=15></td></tr> <tr><td align=center colspan=2><input type=submit value=Login></td></tr> </table> </form> </body> </html
then i have a validationtest.php
PHP Code:
<? session_start(); if ($username=="" || $password=="") { echo "You have to enter your username and password"; include ('login.php'); } else { include ('db.php'); $result=mysql_query("select * from StaffTable where PIN='$username'") or die ("cant do it"); while ($row=mysql_fetch_array($result)) { if ($row["Password"]==$password ) { $name=$row["Name"]; session_register('Name'); $_SESSION['Name'] = $Name; include('tutor.php'); } else { print("Please enter your valid Username and Password!"); include ('login.php'); } } } ?>
after the person is validated then it will directed to tutor.php and this is where my problem started. The problem is after i press the add hours it goes directly to the login form again. what i really want to happen is that after pressing the add hours it will still go on the same page so that the user will be able to log his/her other activities. I hope someone could help me with the code. i'm doing this for the first time.
thank you very much!!!
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Workhours form</title> <script type="text/javascript"> var total = <?php echo (isset($_POST['work_hours_total']) ? $_POST['work_hours_total'] : "0"); ?>; function update1() { document.getElementById("work_hours_total").value = total + Number(document.getElementById("work_hours").value); document.getElementById("remaining_hours").value = 7.5 - Number(document.getElementById("work_hours_total").value); } </script> </head> <body> <?php session_start(); mysql_connect("localhost", "root") or die( "Unable to connect\n". mysql_error() ); mysql_select_db("TEST") or die("Unable to select db ".mysql_error()."\n"); if (isset($_POST['pin'])) { $sql= "insert into StatusTable (PIN, Activity,RegHours) values ('" . $_POST['pin'] . "','" . $_POST['activity'] . "','" . $_POST['work_hours'] . "')"; mysql_query($sql) or die('error making query: ' . mysql_error()); } ?> <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post"> <fieldset> <div> <label for="pin">PIN :</label> <? echo $username ?><br> <label for="name">Name : </label><? echo $name ?> <br> </div> <div> <label for="activity">Activity</label> <input id="activity" name="activity" type="text" size="20"> </div> <div> <label for="work_hours">Work Hours</label> <input id="work_hours" name="work_hours" type="text" size="5" onchange="update()"> </div> <div> <label for="work_hours_total">Total Work Hours</label> <input id="work_hours_total" name="work_hours_total" type="text" size="5" value="<?php echo (isset($_POST['work_hours_total']) ? $_POST['work_hours_total'] : ""); ?>" readonly="true"> </div> <div> <label for="remaining_hours">Hours Remaining</label> <input id="remaining_hours" name="remaining_hours" type="text" size="5" value="<?php echo (isset($_POST['work_hours_total']) ? (7.5 - $_POST['work_hours_total']) : "7.5"); ?>" readonly="true"> </div> <div> <input type="submit" value="Add hours" name="Add"> </div> </fieldset> </form> </body> </html>
|