1

我正在尝试调试以下 PHP 文件,该文件用于服务来自移动应用程序的签入请求,因此我无法使用打印输出来检查程序的流程,因此我想创建一些文件,所以我可以知道程序是如何运行的。但是我不知道在哪里没有创建文件,即使我已经成功地将记录插入到数据库中,任何人都可以帮助我

这是我的PHP代码:

$_Type = $_POST['Type'];
$_ClientID = $_POST['ClientID'];
$_TechID = $_POST['TechID'];
$_SiteID = $_POST['SiteID'];

$content = "First check"; 
$fp = fopen("C:/xampp/htdocs/Me/checking.txt","wb"); 
fwrite($fp,$content); 
fclose($fp);

function checkin($DB, $TechID, $ClientID, $SiteID){
    $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
    if(!$dbConnection){
        die('Error! ' . mysql_error());
        }
    mysql_select_db($DB['database'], $dbConnection);

    $result1 = mysql_query("SELECT COUNT(*) FROM Log") or die('Error! ' . mysql_error());
    $query = "SELECT `Type` FROM `Log` WHERE `TechID` = '".$TechID."' ORDER BY LogTime DESC LIMIT 1";
    $result2 = mysql_query($query) or die('Error! ' . mysql_error());
    while($row1 = mysql_fetch_array($result1)){
        $count = $row1['COUNT(*)'];
        if(mysql_num_rows($result2) > 0){
            while($row2 = mysql_fetch_array($result2)){
                if(trim($row2['Type'])!="Checkin"){
                    $count = $count+1;
                    $timezone = "Asia/Hong_Kong";
                    if(function_exists('date_default_timezone_set')) 
                        date_default_timezone_set($timezone);
                    $Time = date('Y/m/d H:i');

                    mysql_query("INSERT INTO Log (LogID, TechID, ClientID, SiteID, LogTime, Type)
                                VALUES (".$count.", '".$TechID."', ".$ClientID.", ".$SiteID.", '".$Time."', 'Checkin')");
                }else{
                    mail('me@gmail.com', 'Test mail', 'If you can read this, everything was fine!');

                    $content1 = "First 1"; 
                    $fp1 = fopen("C:/xampp/htdocs/Me/checking1.txt","wb"); 
                    fwrite($fp1,$content1); 
                    fclose($fp1);
                }
            }
        }else{
            $count = $count+1;
            $timezone = "Asia/Hong_Kong";
            if(function_exists('date_default_timezone_set')) 
                date_default_timezone_set($timezone);
            $Time = date('Y/m/d H:i');
            mysql_query("INSERT INTO `Log` (`LogID`, `TechID`, `ClientID`, `SiteID`, `LogTime`, `Type`)
                        VALUES (".$count.", '".$TechID."', ".$ClientID.", ".$SiteID.", '".$Time."', 'Checkin')");
        }
    }
}

checkin($DB, $_TechID, $_ClientID, $_SiteID);

如您所见,这是一个用于插入签入记录的程序,但是如果有人在签出之前想再次签入,则应创建一个文件 checks1.txt。但是,执行后不会创建任何检查.txt 或检查1.txt。

4

0 回答 0