gpt4 book ai didi

php - 仅发布使用 while 循环创建的表单中的选择值

转载 作者:行者123 更新时间:2023-11-30 00:25:37 25 4
gpt4 key购买 nike

我对 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);

?>

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>

最佳答案

第一

你必须改变这个

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'>";

关于php - 仅发布使用 while 循环创建的表单中的选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22914639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com