php - 未发布使用 php foreach 生成的第一行的值
问题描述
需要以下代码的帮助。仅在为第一个生成的行点击提交后,“customer_id”的值不会发布。第二项及以下工作按预期进行。
其他页面使用相同的格式进行删除,但不要像这个那样重定向到另一个页面。删除没有问题。
<html>
<!-- the body section -->
<body>
<main>
<section>
<!-- display a table of customers -->
<h2>Results</h2>
<table>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>City</th>
<th> </th>
</tr>
<?php foreach($customers as $cus) : ?>
<tr>
<td><?php echo $cus['firstName'].' '.$cus['lastName']; ?></td>
<td><?php echo $cus['email']; ?></td>
<td class="right"><?php echo $cus['city']; ?></td>
<td><form action="view_and_update.php" method="post" id="search">
<input type="text" name="customer_id" value="<?php echo $cus['customerID']; ?>">
<input name="submit" type="submit" value="Select">
<?php include "redirect.php";?>
</form></td>
</tr>
<?php endforeach; ?>
</table>
</section>
</main>
</body>
</html>
redirect.php 看起来像这样:
<?php
if(isset($_POST["submit"])){
// To redirect form on a particular page
header("Location: view_and_update.php");
}
?>
非常感谢任何帮助。这是一个作业,我们使用 XAMPP/myphpadmin 指定的语言。在任何其他情况下检索、编辑、添加或删除数据都没有问题。这是唯一的问题页面。
解决方案
通过使用以下示例代码,我得到了 view_and_update.php 的正确帖子
它必须是别的东西,而不是代码。
<?php $customers = [
['firstName' => 'Alice', 'lastName' => 'Al', 'email' => 'alison@domain.com', 'city' => 'MyCity', 'customerID' => 123],
['firstName' => 'Bob', 'lastName' => 'Bo', 'email' => 'bob@domain.com', 'city' => 'MyCity', 'customerID' => 124]
]; ?>
<html>
<!-- the body section -->
<body>
<main>
<section>
<!-- display a table of customers -->
<h2>Results</h2>
<table>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>City</th>
<th> </th>
</tr>
<?php foreach($customers as $cus) : ?>
<tr>
<td><?php echo $cus['firstName'].' '.$cus['lastName']; ?></td>
<td><?php echo $cus['email']; ?></td>
<td class="right"><?php echo $cus['city']; ?></td>
<td><form action="view_and_update.php" method="post" id="search">
<input type="text" name="customer_id" value="<?php echo $cus['customerID']; ?>">
<input name="submit" type="submit" value="Select">
</form></td>
</tr>
<?php endforeach; ?>
</table>
</section>
</main>
</body>
</html>
推荐阅读
- c# - 如何修复 Visual Studio 的测试资源管理器中的“活动测试运行已中止”?
- algorithm - 生产者消费者信号量顺序的一个小改动
- powerbi - 如何在 DAX 中为 Power BI 报表编写动态标题
- php - 从大型数据集中获取 OOM
- google-chrome-extension - 是否可以将 chrome 扩展的所有权从一个域转移到另一个组帐户?
- typo3 - TYPO3:我可以删除typo3_src-version 文件夹吗
- donations - 如何接收慈善应用内捐款
- javascript - javascript新手,这适合什么样的主题?
- python-3.x - 使用 LightGBM 示例进行网格搜索
- angularjs - TypeError: XXX undefined with AngularJS $inject Property annotation