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 4 of 4

Thread: maximum Status

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

    Question maximum Status

    hi,
    Anyone who has an idea on how to query the maximum status of my database for a certain map_number. I have fields in my table such as Date, Mapnumber, Employee_number, Workhrs and Status. Everyday the user will input the status of the map he/she is working until it is finished or reached 100%. My goal is if the user enter 10% in the Status yesterday with 01(this is the Mapnumber) and when the user fills up the form today he/she is not allowed to input in the Status less than 10%. If she enters less than 10% then there should be something to inform the user that he/she is not allowed to input less than 10%. I don't have any idea what will be the code for it.

    If there someone here who could help me thanks a lot.

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll give this a shot at a high level, you'll have to get down and dirty because I don't have many details.

    Code:
    function getStatus($mapNum) {
      var $temp_conn=-1;
      var $x_results;
      $temp_conn=mysql_connect(Connection Parameters);
      mysql_select_db(DatabaseName, $temp_conn);
      $qry="SELECT Status FROM tablename WHERE Mapnumber=".$mapNum;
      $x_results=mysql_query($qry,$this->php_con)
                     or die(mysql_error());
      $row=mysql_fetch_array($this->x_results,MYSQL_ASSOC);
      return $row['Status'];
    }
    
    ... <snip> ...
    
    <form ... name="main_frm" onSubmit="return form_Validation(this);">
       <input name="Status" value="<?php echo getStatus($_GET['Status']); ?>">
    
    ... <snip> ...
    
    <script>
       function form_Validation(obj) {
          if(main_frm.Status<0<?php echo getStatus($_GET['Status']); ?>) {
            alert('You can not decrease the Status field.');
            return false;
          }
          return true;
       }
    </script>
    This is the page where the user is entering in the status into a form. The first part is simply a function that queries your database and returns the status. I used the MySQL functions, assuming that is what you are using. If you are using MS-SQL, the query would still work, but you would need to use the mssql... functions. Better yet, find an abstraction class and use it.

    The second section I was just demonstrating how you could set up a simple form validation which will call the javascript function form_Validation(x) onSubmit. I am calling the php getStatus(x) function to default the Status field for the user. I've found that you really have to hold the users' hands when it comes to databases.

    The third section is a javascript function that will return false if the Status is less. Again I am invoking the getStatus function to determine the max Status. If the javascript returns false then the form will not be submitted. This will alert the user to the validation problem before the form is submitted.

    Obviously, this is not enough. When the form is submitted, control is sent to some other page.php which gleans the form data and inserts it into the database, correct? On that page, you will want to include the getStatus(x) function and use PHP to validate the Status once more in the $_POST data. This will prevent users from skirting your javascript validations via URL injections. (i.e., http://somewhere.com/mapapp/submit.p...us=10&MapNum=3 <go>)

    Good luck!

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <form ... name="main_frm" onSubmit="return form_Validation(this);">
    you used the onSubmit within the <form> will this not affect my other codes which does something after submitting it? such as this one
    <label for="work_hours">Work Hours</label>
    <input id="work_hours" name="work_hours" type="text" size="5" value= "0.00" onkeypress = "return onkeypressWrkHrsCheck()" onkeyup = "return onkeyupWrkHrsCheck()" onchange="update1()">

  • #4
    New Coder
    Join Date
    Aug 2004
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    i attached my code. I am able to display the message but I was wondering why it inserts the data in my database although the data entered is an error. hope someone could help me with this.
    Attached Files Attached Files


  •  

    Posting Permissions

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