为什么这个HTML表单只产生8个参数而不是9个?

时间:2012-07-16 08:44:20

标签: php html

我想通过表单将一些参数发送到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文件发送参数,但情况无法解决。

3 个答案:

答案 0 :(得分:5)

你真的没有以这种方式构建你的标记来帮助自己。

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

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

尺寸属性的末尾与名称属性的开头之间没有空格。就选择此值的页面而言,“分钟”值不存在。

将其更改为: -

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

答案 1 :(得分:-1)

使用GET-Method提交表单数据。此方法限制提交数据。使用POST方法。提交数据的空间非常大。

PS:尽量避免使用php编写Html,而是使用正常的方法。

答案 2 :(得分:-1)

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