-1

我想通过表单将一些参数发送到一个php文件以插入数据库,

<html>
<head>
    <title>Self</title>
</head>
<body>
<?php

    function selfcheck($DB, $TechID, $ClientID, $SiteID, $Type, $LogTime){
        $dbConnection = mysql_connect($DB['server'], $DB['loginName'], $DB['password']);
        if(!$dbConnection){
            die('Error! ' . mysql_error());
            }
        mysql_select_db($DB['database'], $dbConnection);
        $result = mysql_query("SELECT COUNT(*) FROM Log") or die('Error! ' . mysql_error());
        while($row = mysql_fetch_array($result)){
            $count = $row['COUNT(*)'];
            $count = $count+1;
            print $count.", ".$TechID.", ".$ClientID.", ".$SiteID.", ".$LogTime.", ".$Type."<br>";
            $query = "INSERT INTO Log (LogID, TechID, ClientID, SiteID, LogTime, Type)
                        VALUES (".$count.", ".$TechID.", ".$ClientID.", ".$SiteID.", ".$LogTime.", ".$Type.")";
            mysql_query($query);
        }
    }

    $LogTime = date('Y/m/d H:i', mktime($_GET['Hour'], $_GET['Minute'], 0, $_GET['Month'], $_GET['Day'], $_GET['Year']));
    selfcheck($DB, $_GET['TechID'], $_GET['ClientID'], $_GET['SiteID'], $_GET['Type'], $LogTime);
?>
</body>

如您所见,有九个 Get 值,但是,当我尝试执行代码时,服务器回复

"Undefined index: Minute in C:\wamp\www\NFC\self.php on line 29", and show in the URL, minute parameter has not been sent. Why does this happen? And how can I solve this problem?

这是发送请求的代码。

print "<form method='get' name='check' action='self.php'>";
    $result = mysql_query("SELECT * FROM Tech") or die('Error! '.mysql_error());
    print "Name<select id='tech' name='TechID'>";
    while($row = mysql_fetch_array($result)){
        print "<option value=".$row['TechID'].">".$row['TechName']."</option>";
    }
    print "</select>";
    $result = mysql_query("SELECT * FROM Client") or die('Error! '.mysql_error());
    print "Name<select id='client' name='ClientID'>";
    while($row = mysql_fetch_array($result)){
        print "<option value=".$row['ClientID'].">".$row['ClientName']."</option>";
    }
    print "</select>";
    $result = mysql_query("SELECT * FROM Site") or die('Error! '.mysql_error());
    print "Name<select id='site'name='SiteID'>";
    while($row = mysql_fetch_array($result)){
        print "<option value=".$row['SiteID'].">".$row['SiteName']."</option>";
    }
    print "</select>";
    print "Type<select id='type' name='Type'>";
    print "<option value='Checkin'>Check In</option>";
    print "<option value='Checkout'>Check Out</option>";
    print "</select><br>";
    print "Year<input type='text' id='year' size='4' name='Year'/>";
    print "Month<input type='text' id='month' size='2' name='Month'/>";
    print "Day<input type='text' id='day' size'2' name='Day'/>";
    print "Hour in 24<input type='text' id='hour' size='2' name='Hour'/>";
    print "Minute<input type='text' id='minute' size'2'name='Minute'/>";
    print "<input type='submit' value='Manual check' onclick='self.php'/>";
    print "</form>";

对于某些选择,它位于 PHP 文件中,我想从数据库中获取选项,而不是对它们进行硬编码。我曾尝试通过 javascript 文件发送参数,但情况无法解决。

4

3 回答 3

5

以这种方式构建标记实际上并没有帮助自己。

我怀疑你的答案在这里: -

print "Minute<input type='text' id='minute' size'2'name='Minute'/>";

size属性的结尾和name属性的开头之间没有空格。就拾取该值的页面而言,“分钟”值不存在。

将其更改为:-

print "Minute<input type='text' id='minute' size='2' name='Minute'/>";
于 2012-07-16T08:51:03.543 回答
-1

使用 GET 方法提交表单数据。此方法对提交数据有限制。使用 POST 方法。提交数据的空间非常无限。

PS:尽量避免用php写Html,改用正常方式。

于 2012-07-16T08:49:13.017 回答
-1

在 PHP ini 文件中,您可以发现max_input_time&post_max_size这两个常量都会影响 POST 或 GET 数据。在 GET 的情况下,最大 URL 长度也适用。

于 2012-07-16T08:52:07.837 回答