0

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

首先,这是我以前从未解决过的问题,所以如果这对经验更丰富的开发人员来说是直截了当的,请多多包涵。

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

            $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");

                            }
                            ?>

我要做的是为每个 Location 记录添加两个提交按钮,一个将用户带到一个名为的页面updatelocation.php,第二个将用户带到一个名为addfinds.php. 但两者都必须通过“locationid”字段链接到位置。所以换句话说,如果用户想要Add FindsLocation 1点击相关按钮时,他们会被带到Add Finds位置 1 的页面。

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

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

非常感谢和亲切的问候

4

1 回答 1

0

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

formaction.php示例:

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

    header("Location: " . $url);
}

与 formaction.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");

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

于 2012-06-13T15:01:57.043 回答