|
Subject:
|
totally weird problem with a script
|
|
Posted By:
|
tsavalia
|
Post Date:
|
8/7/2006 6:12:35 PM
|
when my script tries to update a table row with time field, it updates the row but it also add a new row with the time value 50 seconds later than the original time value in update statement. So i think, after it updates the row, the script again executes by itself and do the insert. I don't know whats going on. Any help would be appreciated.. PLEASE HELP.... here is the code, ----------------------------------- <?php ob_start(); ?> <?php session_start(); ?> <html> <head> <title>Authentication</title> <script language="javascript"> window.resizeTo(320,260) window.moveTo(300,200) </script>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin=10 leftmargin=10> <?php if (isset($_REQUEST['Submit'])){ if($_REQUEST['Submit'] == "Confirm"){ $str = "select pwd from tblEmpMaster where empName = '".urldecode($_REQUEST['chkEmpName'])."' and officeID = '".$_SESSION['officeID']."'"; mysql_connect("localhost","tsavalia","titodi"); mysql_select_db("timeclock"); $rs1 = mysql_query($str); echo $str."<BR>"; if (mysql_num_rows($rs1) > 0){ while ($row1 = mysql_fetch_row($rs1)){ if ($row1[0] != $_REQUEST['userpwd']){ echo "<p><font size=3>Wrong Password</font></p>"; mysql_free_result($rs1); header("Location: confirmpwd.php?chkEmpName=".urlencode($_REQUEST['chkEmpName'])."&auth=false"); } else { $str1 = "select * from tblTimeClock where empName = '".$_REQUEST['chkEmpName']."' and forDate = '".date("y/m/d")."'"; echo $str1."<BR>"; $rs2 = mysql_query($str1); if (mysql_num_rows($rs2) > 0) { $lastrow = mysql_data_seek($rs2,mysql_num_rows($rs2)-1); echo mysql_num_rows($rs2)."<BR>"; //echo mysql_field_name($rs2,4)."<br>"; while ($row2 = mysql_fetch_row($rs2)){ if (is_null($row2[3]) == False && is_null($row2[4]) == False) { $str2 = "Insert into tblTimeClock(forDate,empName,in1) values('".date("y/m/d")."','".$_REQUEST['chkEmpName']."','".strftime("%H:%M:%S")."')"; echo $str2; mysql_query($str2); echo "<script language=\"javascript\">alert('You are punched in');window.opener.location.reload();self.close();</script>"; } elseif (is_null($row2[3]) == False && is_null($row2[4]) == True) { $str2 = "Update tblTimeClock set out1 = '".strftime("%H:%M:%S")."' where empName = '".$_REQUEST['chkEmpName']."' and forDate = '".date("y/m/d")."' and ID = ".$row2[0]; echo $str2; mysql_query($str2); echo "<script language=\"javascript\">alert('You are punched out');window.opener.location.reload();self.close();</script>"; } } } else{ echo mysql_num_rows($rs2); $str2 = "Insert into tblTimeClock(forDate,empName,in1) values('".date("y/m/d")."','".$_REQUEST['chkEmpName']."','".strftime("%H:%M:%S")."')"; echo $str2; mysql_query($str2); echo "<script language=\"javascript\">alert('You are punched in');window.opener.location.reload();self.close();</script>"; } mysql_free_result($rs2); } } } mysql_free_result($rs1); } }
?> <form name="form1" method="get" action="confirmpwd.php"> <table border="1" bordercolor="#CCCCCC" cellspacing="0" cellpadding="0" align="left" bgcolor="#006600" valign="top" width="250"> <?php if(isset($_REQUEST['auth'])){ if($_REQUEST['auth'] == "false"){ echo "<tr bgcolor='white'><td colspan=2><font face='arial' size=3 color='red'>Wrong Password</font></td></tr>"; } } ?> <tr bgcolor="#006600"> <td height="36" colspan=2> <div align="center"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><b>Identity: <?php if(isset($_REQUEST['chkEmpName'])) echo str_replace("+"," ",$_REQUEST['chkEmpName']); ?></b></font> </td> </tr> <tr bgcolor="#FFFFFF" height="29"> <td align="center"><b><font size="2" face="Arial" color="maroon">Password </font></b></td> <td align="center"> <input type="password" name="userpwd" size=15> <input type="hidden" name="chkEmpName" value="<?php if(isset($_REQUEST['chkEmpName'])){ echo str_replace("+"," ",$_REQUEST['chkEmpName']); } ?>"> </td> </tr> <tr bgcolor="#FFFFFF" height="29"> <td align="center" colspan=2> <input type="submit" name="Submit" value="Confirm"> </td> </tr> </table> </form> <script language="javascript">document.form1.userpwd.focus();</script> </body> </html> <?php ob_end_flush(); ?>
|
|