Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2006, 06:12 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default totally weird problem with a script

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>Wrong Password</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>Wrong Password</td></tr>";
               }
          }
    ?>
    <tr bgcolor="#006600">
      <td height="36" colspan=2>
        <div align="center"><b>Identity: <?php if(isset($_REQUEST['chkEmpName'])) echo str_replace("+"," ",$_REQUEST['chkEmpName']); ?></b>
      </td>
    </tr>
    <tr bgcolor="#FFFFFF" height="29">
        <td align="center"><b>Password </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(); ?>






Similar Threads
Thread Thread Starter Forum Replies Last Post
weird problem! Please Help johnjohn Classic ASP Databases 5 December 21st, 2004 10:27 AM
Weird Access Problem MattyJ Access 2 October 1st, 2004 02:10 PM
weird Oracle problem! pankaj_daga Oracle 2 July 12th, 2004 09:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.