如何为表单操作创建唯一的$_POST


How to make a unique $_POST to a form action?

我很难找到解决方案。在这种情况下,假设我在数据库中有5本书,我将通过执行while来显示它们,然后mysql_fetch_array假设我创建了一个表。这是的绘图

echo"
<td>
<form action='bookext.php' method='post'>
<input type='submit' value='".$row['book_title']."'  style='border: 0; background: transparent';>WHAT TO PUT HERE</form></td>";

CCD_ 3工作良好,因为它必须在数据库中显示书籍的标题。但是,如何获取它的唯一值book_id并将其发送到bookext.php
PS:对不起我的标题,我无法提取正确的英文

首先,您当前的输入需要一个名称属性:

 "<input type='submit' name="title" value='".$row['book_title']."'  style='border: 0; background: transparent';>WHAT TO PUT HERE</form></td>";

由于您使用POST方法,这将确保该值在$_POST数组中可用,如$_POST['title']

对于id,您可以在表单中添加隐藏输入:

"<input type='hidden' name='book_id' value='".$row['book_id']."'>"

当您提交时,这将在$_POST['book_id']中提供给您。

只需在表单中插入隐藏字段

<input type="hidden" name="POST_NAME" value="YOUR_VALUE_TO_IDENTIFY">

不要在表中使用表单。

<form action='bookext.php' method='post'>
<table>
<tr>
<?php foreach($books AS $book){ ?> 
<td>
  <button type="submit" name="bookId" value="<?php echo $book['id']; ?>">
    Title of the book
  </button>
</td>
<?php } ?>
</tr>
</table>
</form>

bookext.php

<?php
$id = $_POST['bookId'];