每个人我都想为我的工作建立一份End of Shirt报告,我试图让数据库结构尽可能简单,我只有3列。我遇到的问题是列是与输入名称相同的名称,基本上唯一标识符是我有的隐藏输入区别于彼此,我选择这种方法有53个单独的列,因为我想能够在未来进行更多定制。
我基本上想要的是"隐藏"输入进入类别,然后值是用户输入的部分,日期是自动部分。
问题就在于你们所有人都会想到的,它只会将我的一个字段输入数据库,因为它们的名称相同。这是什么,只有我在报名表中的最后一个字段。我想在两边保持相同的名称,以便更容易地导航数据库,并且在整个过程中更容易编辑。如果有一种更简单或更简单的方式,我也倾向于尝试这种方式。
谢谢!
这是我的源代码,基本的html标题:
<html>
<head>
<title>OAK3 - EOS Dashboard</title>
</head>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;border-color:#aabcfe;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 8px;border-style:solid;border-width:1px;border-color:#aabcfe;color:#669;background-color:#e8edff;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;border-color:#aabcfe;color:#039;background-color:#b9c9fe;}
.tg .tg-hgcj{font-weight:bold;text-align:center;}
.tg .tg-031e{text-align:center;}
a:visited {color:blue;text-decoration:none;}
</style>
MySQL连接
<?
$usr = "root";
$pwd = "password";
$db = "test";
$host = "localhost";
# connect to database
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if (mysql_error()) { print "Database ERROR: " . mysql_error();
}
?>
<center>
<body>
MySQL REPLACE部分
<?
// define variables and set to empty values
$category = $value = "";
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
# escape data and set variables
$category = addslashes($_POST["category"]);
$value = addslashes($_POST["value"]);
# setup SQL statement
$sql = " REPLACE INTO oak3_eos_dashboard (category, value, date) VALUES ";
$sql .= " ('$category', '$value', curdate()) ";
#execute SQL statement
$result = mysql_query($sql, $cid);
# check for error
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
print "<h3><font color=red>EOS information Added! - View it <a href=eos_summary.php>HERE</a></font></h3>";
}
?>
表格
<center><h2>OAK3 - EOS Recap</h2></center><hr>
<form name="fa" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<?php
echo "Today's Date " . date('M/d/Y h:i:s');
?>
<table border=1 cellpadding=1 cellspacing=1 class="tg">
<tr><th class="tg-hgcj" colspan=2 align=center><b>Shift Performance</b></td></tr>
<tr><td><input type="hidden" name="category[]" value="Shipped Units Actual">Shipped Units Actual</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Shipped Units Planned">Shipped Units Planned</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="TPH Actual">TPH Actual</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="TPH Planned">TPH Planned</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Callouts">Callouts</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><th class="tg-hgcj" colspan=2 align=center><b>Safety</b></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Safety Incidents">Number of Safety Incidents</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Safety Saves">Number of Safety Saves</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of FSI/5S Observations">Number of FSI/5S Observations</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Safety Incident Link(s)">Safety Incident Link(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of TDR Audtis">Number of TDR Audtis</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of TDR Failures">Number of TDR Failures</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="TDR Failure Details">TDR Failure Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="TDR Root Cause">TDR Root Cause</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><th class="tg-hgcj" colspan=2 align=center><b>Quality</b></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Pack Audits">Number of Pack Audits</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Pack Failures">Number of Pack Failures</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Pack Details">Pack Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Pack Audits Root Cause">Pack Audits Root Cause</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Missort Audits">Number of Missort Audits</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Missort Failures">Number of Missort Failures</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Missort Details">Missort Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Missort Root Cause">Missort Root Cause</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 1">Quality Focus Metric 1</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 1 : Actual Value">Quality Focus Metric 1 : Actual Value</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 1 : Details">Quality Focus Metric 1 : Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 1 : Countermeasure(s)">Quality Focus Metric 1 : Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 2">Quality Focus Metric 2</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 2 : Actual Value">Quality Focus Metric 2 : Actual Value</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 2 : Details">Quality Focus Metric 2 : Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Quality Focus Metric 2 : Countermeasure(s)">Quality Focus Metric 2 : Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><th class="tg-hgcj" colspan=2 align=center><b>Customer Experience</b></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Failed ExSD for Fast Track & Premium - Missed CE">Number of Failed ExSD for Fast Track & Premium - Missed CE</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Failed ExSD for Fast Track & Premium - Missed CE: Details">Failed ExSD for Fast Track & Premium - Missed CE: Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Failed ExSD for Fast Track & Premium - Missed CE: Countermeasure(s)">Failed ExSD for Fast Track & Premium - Missed CE: Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Failed ExSD for FT & Prem - Late SLAM">Number of Failed ExSD for FT & Prem - Late SLAM</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Failed ExSD for FT & Prem - Late SLAM: Details">Failed ExSD for FT & Prem - Late SLAM: Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Failed ExSD for FT & Prem - Late SLAM: Countermeasure(s)Failed ExSD for FT & Prem - Late SLAM: Countermeasure(s)">Failed ExSD for FT & Prem - Late SLAM: Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Number of Failed ExSD for Standard - Late SLAM">Number of Failed ExSD for Standard - Late SLAM</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Failed ExSD for Standard - Late SLAM: Details">Failed ExSD for Standard - Late SLAM: Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Failed ExSD for Standard - Late SLAM: Countermeasure(s)">Failed ExSD for Standard - Late SLAM: Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Late SLAM - Root Cause">Late SLAM - Root Cause</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><th class="tg-hgcj" colspan=2 align=center><b>Productivity</b></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 1">Productivity Focus Metric 1</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 1: Actual Value">Productivity Focus Metric 1: Actual Value</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 1: Details">Productivity Focus Metric 1: Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 1: Countermeasure(s)">Productivity Focus Metric 1: Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 2">Productivity Focus Metric 2</td><td><input type="text" size="2" name="value"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 2: Actual Value">Productivity Focus Metric 2: Actual Value</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 2: Details">Productivity Focus Metric 2: Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 2: Countermeasure(s)">Productivity Focus Metric 2: Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 3">Productivity Focus Metric 3</td><td><input type="text" size="2" name="value"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 3: Actual Value">Productivity Focus Metric 3: Actual Value</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 3: Details">Productivity Focus Metric 3: Details</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="Productivity Focus Metric 3: Countermeasure(s)">Productivity Focus Metric 3: Countermeasure(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><th class="tg-hgcj" colspan=2 align=center><b>Misc.</b></td></tr>
<tr><td><input type="hidden" name="category[]" value="Ticket Number Link(s)">Ticket Number Link(s)</td><td><input type="text" size="2" name="value[]"></td></tr>
<tr><td><input type="hidden" name="category[]" value="AM/OPS Present">AM/OPS Present</td><td><input type="text" size="2" name="value[]"></td></tr>
</table>
<br>
<input type="submit" name="save" id="save" value="Save">
</form>
</body>
剪切表格
插入数据库的所有内容都是:
更新了REPLACE语句
这是我更新的REPLACE部分,现在它将值输入到Category列中并输入到日期字段中,但是对于value列,没有任何内容进入这些字段
<?
// define variables and set to empty values
$category = $value = "";
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
foreach($_POST['category'] as $i => $category)
{
// Get values from post.
$category = mysql_real_escape_string($category);
$value = mysql_real_escape_string($_POST['value'][$i]);
// Add to database
$sql = "REPLACE INTO `oak3_eos_dashboard` (`category`, `value`, `date`) VALUES ('".$category."', '".$value."', curdate())";
$result = mysql_query($sql);
}
# check for error
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
print "<h3><font color=red>EOS information Added! - View it <a href=eos_summary.php>HERE</a></font></h3>";
}
?>
新结果