我做了一个php页面。我正在其上显示来自我的数据库的表"产品"。 每一行都很好地显示。 今天,我尝试在表格的每一行末尾添加一个名为"rate"的按钮。我成功地做到了。现在我想在单击该按钮时将该行第一列的值发送到另一个 php 页面。我被困住了,该怎么做?你能帮忙吗?
我知道我必须在我的表单中使用方法post,并且我必须在另一个php页面上使用$_post[that value]
来灌输进一步功能的价值。
我只需要问在哪里添加按钮行中第一列的值。 以便 onclick 它可以发送该值。 我希望我清楚这一点。非常感谢您的帮助:)
<?php
include("connection.php");
$query = "select * from prod";
$res = oci_parse($conn,$query);
usleep(100);
if (oci_execute($res)){
usleep(100);
print "<TABLE border '"1'">";
$first = 0;
while ($row = @oci_fetch_assoc($res)){
if (!$first){
$first = 1;
print "<TR><TH>";
print implode("</TH><TH>",array_keys($row));
print "</TH></TR>'n";
}
print "<TR><TD>";
print @implode("</TD><TD>",array_values($row));
print "</TD></TR>'n";
echo "<td><form action='detailform.php' method='POST'><input type='submit' name='submit-btn' value='Rate'/></form></td></tr>";
}
print "</TABLE>";
}
?>
你必须在你的表单中添加你喜欢的任何类型的输入
echo "<td>
<form action='detailform.php' method='POST'>
<input type='hidden' name='your_val_key' value='".$row[your_val_key_in_query]."'> <!-- input hidden, change to text 4 debug -->
<input type='submit' name='submit-btn' value='Rate'/>
</form>
</td></tr>";
而且,在您的detailform.php
中,您可以获得 val
echo $_POST["your_val_key"];
如果您不确定您发送了多少数据或其他内容,请尝试此操作,您将获得完整的数据:
echo "<pre>".print_r($_POST,true)."</pre>";
顺便说一句:你为什么要混合印刷和回声?
使用隐藏输入
echo "<td><form action='detailform.php' method='POST'><input type='hidden' name='col-name' value='you-col-value'><input type='submit' name='submit-btn' value='Rate'/></form></td></tr>";