Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: forms

  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question forms

    hi,
    i would like to ask for help. actually i'm doing a statuslog form. the user has to login first before he could go to the statuslog form. the login is ok. the statuslog form contain the entered PIN and name of the user . The user has to input all the activities with the corresponding workhours. However, he could only input the activities one at time so i have a Add Hours button. My problem now is after i press the Add Hours button it is returning to the login page.

    What i really want to happen is that after pressing the "Add Hours" it should return to the same page and the PIN and Name of the user is still there and the corresponding remaining hours and work hours and total work hours are also there inorder for the user to add another activities. it will only return to the login page if he presses the logout button.

    Is there someone who could help me with the code?

    Thanks.


    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 update()
                {
                    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
            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="" 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>

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm. not sure about your setup.

    normally, this is what you do:
    - on top of the formpage, you see if a sessionvariable is set (al loginflag) and if this flag isn't set, you redirect to the loginform. Like
    PHP Code:
    // at the top of the page
    session_start();
    if (!
    $_SESSION['logedin']){
       
    header('Location: login.php');
       die();

    - in your loginpage, when you proces the submitted user and pin, you set the loginflag
    PHP Code:
    // at the top of the page
    session_start();
    //some other code to validate the login etc
    $_SESSION['logedin']=True
    You can also store the value of the pin etc in sessionvariables
    - when you then proces the form where they input the hours etc, you then check if the form was submitted or if the pagfe is requested for the first time. Like
    PHP Code:
    if ($_POST['Add']=='Add Value'){
            
    mysql_connect("localhost""root"
            or die( 
    "Unable to connect\n"mysql_error() ); 
    ...
            
    mysql_query($sql) or die('error making query: ' mysql_error()); 


    Note --> better put the connection and db-selectionstrings in a seperate file that you then include.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i really need your instruction bout this one. this is the very first time i'm doing this and i'm on the process of learning it by myself.

    thanks. hoping for your response.

    actually this is my login page
    PHP Code:
    <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
    this is my validationtest.php
    PHP Code:
    <?
    if ($username=="" || $password=="")
    {
        echo 
    "You have to enter your username and password";
        include (
    'login.php');
    }

    else
    {
        
    mysql_connect("localhost""root") or
        die (
    "Could not connect to database");

        
    mysql_select_db("dals") or
        die (
    "Could not select database");

    $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"];
          include(
    'tutor.php');
     
    //   printf("Successfully Logged In!");
        
    }

    else
        {
        print(
    "Please enter your valid Username and Password!");
        include (
    'login.php');
        }
     }
    }
    ?>

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    What version of PHP are you using?

  • #5
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    php 4.2.2.

    i really need help with this one. i'm trying but having difficulty.

    thanks

  • #6
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    try this?
    PHP Code:
    <? 
    if($username != "" && $password != ""){
    $con mysql_connect("localhost""root""password") or die("Could not connect to database"); 
    mysql_select_db("dals",$con) or die("Could not select database"); 

    $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"]; 
         include(
    'tutor.php'); 
          
    //   printf("Successfully Logged In!"); 
     

    else{ 
       echo 
    "Please enter your valid Username and Password!"
       include(
    'login.php'); 


    }else{
        echo 
    "You have to enter your username and password"
        include (
    'login.php');
    }
    ?>
    If that doesnt work, try putting this above the first if(

    PHP Code:
    $username $_POST['username'];
    $password $_POST['password']; 
    Last edited by boeing747fp; 10-01-2004 at 08:50 PM.

  • #7
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks but it still goes back to the login form after pressing the add hours which is supposed to go back to the same page for logging another activity.

    any other idea how would i do it? i really don't know what's missing with my code. i'm on a step by step learning it.

    hoping for some more help guys. thanks

  • #8
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    you dont have an action="" set or method="" set in the HTML form for the Add Hours

  • #9
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you dont have an action="" set or method="" set in the HTML form for the Add Hours
    I've already put this on my form for Add hours
    <form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
    but still it goes back to my login form after pressing the add hours.

    thanks a lot for spending sometime on my query. If you still have any ideas pls. tell me.

    hoping for your response.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •