我是HTML和SQL的新手,所以我所做的一切都是通过这个和其他在线网站自学。我根据数据库中的条目数创建了许多表单。这个数字可能会有大约50个条目。基本上,我想要做的是创建一个提交按钮,将三条信息发布到第二个数据库。这些信息是部件号(始终是唯一值),固化时间和印刷机编号。我知道我的问题的一部分是赋予值唯一的名称,所以提交知道它将使用什么数据,但我似乎无法弄清楚正确的格式。目前,我只想将$ partnum变量传递给第二个数据库。我可以从那里向后逆向工程以完成剩下的工作。
PHP代码
function press_list($partnum)
{
echo "<select name=\"Press_used".$partnum."\"style=\"float:right\">";
echo "<option selected>---</option>";
echo "<option value =\"A1-T\">A1-T</option>";
... <-- other options omitted to save space
echo "<option value =\"A10-B\">A10-B</option>";
echo "</select>";
}
function load_button($cureleft)
{
if ($cureleft <= 0)
{
echo "<input type=\"submit\" value=\"Loading\" />";
}
else
{
echo "<input type=\"submit\" value=\"Loading\" disabled>";
}
}
while($row = mysqli_fetch_array($result))
{
$partnum = $row['Part_Number'];
echo "<form action=\"loadpost.php\" name=\"".$row['Part_Number']."\">";
echo "<fieldset>";
echo "<h3>".$row['Part_Number']."</h3>";
echo "<input type=\"hidden\" name=\"".$partnum."\" value=\"".$partnum."\">";
echo "<p class=\"center\">".$row['New_#']."</p>";
echo "<p class=\"center\">Size: <b>".$row['Tire_Size']."</b></p>";
echo "<p class=\"leftalign\">Tread: ";
echo $row['Type_&_Tread'];
$weight=number_format($row['Build_Weight'],1);
echo "<span class=\"rightalign\">Weight: ".$weight."</span></p>";
echo "<p class=\"box\">--Notes--";
echo "<br><span class=\"center\">".$row['NOTES']."</span></p>";
echo "<p class=\"leftalign\">Scheduled Press: ";
echo $row['Press'];
press_list($partnum);
echo "</p>";
echo "<p class=\"leftalign\">Cure time: ";
echo ($row['Cure_Time']*60);
$cureleft = (($row['Cure_Time']*60)-190);
echo "<span class=\"rightalign\">Cure left: ".$cureleft."</span></p>";
load_button($cureleft);
echo "</fieldset>";
echo "</form>
";
}
mysqli_close($con);
&GT;
Loadpost.php
<?php
$con=mysqli_connect("localhost","root","admin","floortracking");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO loaded (Cure, Time, Tire, Press)
VALUES ('53',now(),'$_POST[$partnum]','$_POST[Press_used]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "<p>1 record added</p>";
mysqli_close($con);
?>
一种表单HTML
<form action="loadpost.php" name="01-590905-001R"><fieldset><h3>01-590905-001R</h3><input type="hidden" name="partnum" value="01-590905-001R"><p class="center">20005133</p><p class="center">Size: <b>RECLAIM</b></p><p class="leftalign">Tread: BO2K<span class="rightalign">Weight: 56.0</span></p><p class="box">--Notes--<br><span class="center">RECLAIM</span></p><p class="leftalign">Scheduled Press: A1-T<select name="Press_used" style="float:right"><option selected>---</option><option value ="A1-T">A1-T</option><option value ="A1-M">A1-M</option><option value ="A1-B">A1-B</option><option value ="A2-T">A2-T</option><option value ="A2-B">A2-B</option><option value ="A3-T">A3-T</option><option value ="A3-M">A3-M</option><option value ="A3-B">A3-B</option><option value ="A4-T">A4-T</option><option value ="A4-B">A4-B</option><option value ="A5-T">A2-T</option><option value ="A5-B">A2-B</option><option value ="A6">A6</option><option value ="A7-T">A7-T</option><option value ="A7-B">A7-B</option><option value ="A8-T">A8-T</option><option value ="A8-B">A8-B</option><option value ="A9-T">A9-T</option><option value ="A9-B">A9-B</option><option value ="A10-T">A10-T</option><option value ="A10-B">A10-B</option></select></p><p class="leftalign">Cure time: 180<span class="rightalign">Cure left: -10</span></p><input type="submit" value="Loading" ></fieldset></form>
答案 0 :(得分:0)
第一
你必须改变 此
echo "<input type=\"hidden\" name=\"".$partnum."\" value=\"".$partnum."\">";
到这个
echo "<input type=\"hidden\" name='partnum' value=\"".$partnum."\">";
由于每个表单中都有一个提交按钮,因此它们将提交它们所在的表单。您无需担心提交正确的表单。不会提交任何其他输入字段,不在该表单内,您是从
提交的第二
您无需在每个选择
中回显partnum更改此
echo "<select name=\"Press_used".$partnum."\"style=\"float:right\">";
进入这个
echo "<select name=\"Press_used\"style=\"float:right\">";
第三,sql
$sql="INSERT INTO loaded (Cure, Time, Tire, Press)
VALUES ('53',now(),'$_POST[$partnum]','$_POST[Press_used]')";
$sql="INSERT INTO loaded (Cure, Time, Tire, Press)
VALUES ('53',now(),'".$_POST['partnum']."','".$_POST["Press_used"]."')";
我认为这都是
更新
此:
echo "<form action=\"loadpost.php\" name=\"".$row['Part_Number']."\">";
进入这个:
echo "<form action=\"loadpost.php\" name=\"".$row['Part_Number']."\" method='POST'>";
答案 1 :(得分:0)
请查看Loadpost.php中的$ _Post-Array。
我知道我的问题的一部分是赋予值唯一名称
正确。更改表单中输入/选择字段的名称属性。仅使用静态名称。
echo "<input type=\"hidden\" name=\"partnum\" value=\"".$partnum."\">";
和
echo "<select name=\"Press_used\"style=\"float:right\">";
Loadpost.php:
现在您可以访问$ _POST中的值:
$_POST['partnum']
$_POST['Press_used']