需要以下代码的协助。仅在第一个生成的行上单击“提交”后,“ 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指定的语言。在任何其他情况下,检索,编辑,添加或删除数据都没有问题。这是唯一的问题页面。
答案 0 :(得分:0)
通过使用以下示例代码,我将正确的帖子发布到了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>