View Full Version : maximum Status

10-15-2004, 11:16 AM
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. :confused:

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

10-15-2004, 07:00 PM
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.

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;
or die(mysql_error());
return $row['Status'];

... <snip> ...

<form ... name="main_frm" onSubmit="return form_Validation(this);">
<input name="Status" value="<?php echo getStatus($_GET['Status']); ?>">

... <snip> ...

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;

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.php?Status=10&MapNum=3 <go>)

Good luck! :thumbsup:

10-16-2004, 01:40 AM
<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()">

10-18-2004, 07:14 AM
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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum