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