多个提交按钮链接回主记录


Multiple Submit Buttons Linked Back To Main Record

我想知道是否有人可以帮助我。

首先,这是我以前从未解决过的问题,所以如果这对经验丰富的开发人员来说是直接的事情,请耐心等待。

下面的代码是脚本的一部分,它正确显示每个用户的"位置列表"。

            $i=0;
                    while ($i < $num) {
                        $lid=mysql_result($result,$i,"locationid");
                        $lname=mysql_result($result,$i,"locationname");
                        $laddress=mysql_result($result,$i,"returnedaddress");
                        include("admin/link.php");
                        include("admin/opendb.php");
                        $fquery = "SELECT COUNT(*) num FROM finds WHERE locationid = '$lid'";
                        $fcount = mysql_query($fquery) or die('error');
                        $row = mysql_fetch_assoc($fcount);
                        $findscount = $row['num'];
                        mysql_close($connect);  
                        ?>
                        <table width="603" border="0">
                      <tr>
                        <th width="156">Location</th>
                        <th width="302">Address</th>
                        <th width="131">No. Of Finds Made</th>
                      </tr>
                      <tr>
                        <td><?php echo $lname;?></td>
                        <td><?php echo $laddress;?></td>
                        <td><?php echo $findscount;?></td>
                      </tr>
                        </table>
                        <?php
                        echo'<form name="locations" method="post">';
                                    $i++;
                    }
                    if ($num == 0) {
                        echo"<tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                              <td colspan='3'><div align='center'><strong>No locations have been added yet. <a href='saveaddress.php'>Click here</a> to add one.</strong></div></td>
                              <td>&nbsp;</td>
                            </tr>
                            <tr>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td>
                            </tr>";
                    }

                            echo '<input type="submit" name="submitlocation" id="submitlocation" value="View/Amend Location Details">';
                            echo '<input type="submit" name="submitfinds" id="submitaddfinds" value="Add Finds">';
                            echo '</div>'."'n";
                            if(isset($_POST["submitlocation"])) {
                                  header("updatelocation.php");
                              }
                              else if(isset($_POST["submitaddfinds"])) {
                                  header("addfinds.php");
                            }
                            ?>

我正在尝试为每个位置记录添加两个提交按钮,一个将用户带到名为updatelocation.php的页面,另一个将用户带到名为addfinds.php的页面。但两者都必须通过"位置 ID"字段链接到位置。因此,换句话说,如果用户想要在单击相关按钮后Add Finds Location 1,则会将他们带到位置 1 的Add Finds页面。

我已经

阅读了许多教程,但我显然误解了某些地方,因为尽管我已经设法将按钮添加到记录中,但当我单击任一按钮时,"位置列表"会刷新,而不是将用户带到相应的页面。

只是想知道是否有人可以看看这个,让我知道我哪里出错了?

非常感谢和亲切的问候

最好创建一个单独的页面(即forrmaction.php),来处理逻辑并将用户发送到正确的页面。如果您不想这样做,还可以为每个按钮创建一个单独的窗体,只需将formaction 属性设置为指向 updatelocation.php 或 addfinds.php

模板示例.php

if (isset($_POST['type']) {
    if ($_POST['type'] == 'update')
        $url = 'updatelocation.php';
    else
        $url = 'addthis.php';
    header("Location: " . $url);
}

具有两个按钮的表单示例,该按钮适用于表单操作.php:

<form name="locations" method="POST" action="formaction.php">
     <input type="submit" name="type" value="update">
     <input type="submit" name="type" value="add">
</form>

但是,对于您的问题,问题是您没有使用正确的标题。要使用重定向,您必须在标头中使用"位置:"。例如

header("Location: updatelocation.php");

请注意,因为如果标头已经发送,这将不起作用。在这种情况下,您可能需要查看输出控制。