0

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

我觉得我需要一双全新的眼睛来看待我无法解决的问题。

下面的表格用于列出Location records保存在 MySQL 数据库中的内容。

    <form name="locationsconsole" id="locationsconsole" method="post" action="locationsaction.php">

                                    <?php

                                        $query = "SELECT * FROM `table` WHERE `userid` = '$idnum' ORDER BY locationname";
                                        $result = mysql_query($query) or die('error');
                                        $num = mysql_numrows($result);
                                        mysql_close($connect);                  
                                        $i=0;
                                        while ($i < $num) {
                                        $lid=mysql_result($result,$i,"locationid");
                                        $lname=mysql_result($result,$i,"locationname");
                                        $laddress=mysql_result($result,$i,"returnedaddress");

                             <tr>
                                <td><input type="text" id="lid" name="lid" value="<?=$lid?>"/></td>
                                <td><div align="center"><?php echo $lname;?></div></td>
                                <td><div align="left"><?php echo $laddress;?></div></td>
                                <td><div align="center"><?php echo $findscount?></div></td>
                                <td><div align="center"><input name="type" type="submit" value="View Details"/></div></td>
                                <td><div align="center"><input name="type" type="submit" value="Add Finds"/></div></td>
                                <td><div align="center"><input name="type" type="submit" value="Add Images"/></div></td>
                                <td><div align="left"><input name="type" type="submit" value="View Location Finds"/></div></td>
                            </tr>

    </form>

使用下面的代码,我表单末尾的四个按钮将用户带到四个单独的屏幕,所有屏幕都链接回Location record通过$lid variable.

<?php session_start();
$_SESSION['lid'] = $_POST['lid'];
if (isset($_POST['type'])) {
    $urls = array(
        'View Details' => 'viewlocation.php',
        'Add Finds' => 'addfinds.php',
        'Add Images' => 'addimages.php',
        'View Location Finds' => 'locationfinds.php'
    );
    $url = $urls[$_POST['type']];
    header("Location: " . $url);
}
?>

因此,所有四种接收表格都$lid = $_SESSION['lid'];在每一页的顶部都有这个来捕获这个变量。

这种架构直到几天前都运行良好,现在一切都出错了,我不知道为什么。我知道<input type="text" id="lid" name="lid" value="<?=$lid?>"/>我表单中的这个字段的值是正确的。

但是,无论有多少Locations records,如果我点击任何按钮,我都会被带到正确的接收屏幕,但它总是针对列表中的最后一个“位置”记录。

我似乎无法找到我在这里做错了什么,或者理解为什么它现在开始给我带来问题。我检查了 Chrome 中的 JavaScript 控制台,也没有显示任何错误。

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

非常感谢和亲切的问候

4

2 回答 2

1

你有一个错字:

'mysql_numrows'

应该:

'mysql_num_rows'

于 2012-06-27T12:21:49.223 回答
1

您所有的“盖子”输入都采用相同的形式。当您提交表单时,会发送所有值,并且只有最后一个值会进入您的 $_POST 数组。将表单标签移动到循环内部(这意味着生成许多表单)它应该可以正常工作。

<?php

$query = "SELECT * FROM `table` WHERE `userid` = '$idnum' ORDER BY locationname";
$result = mysql_query($query) or die('error');
$num = mysql_num_rows($result);
mysql_close($connect);
$i = 0;
while ($i < $num) {
    $lid=mysql_result($result,$i,"locationid");
    $lname=mysql_result($result,$i,"locationname");
    $laddress=mysql_result($result,$i,"returnedaddress");

    ?><form name="locationsconsole" id="locationsconsole" method="post" action="locationsaction.php">
        <table>
            <tr>
                <td><input type="text" id="lid" name="lid" value="<?=$lid?>"/></td>
                <td><div align="center"><?php echo $lname;?></div></td>
                <td><div align="left"><?php echo $laddress;?></div></td>
                <td><div align="center"><?php echo $findscount?></div></td>
                <td><div align="center"><input name="type" type="submit" value="View Details"/></div></td>
                <td><div align="center"><input name="type" type="submit" value="Add Finds"/></div></td>
                <td><div align="center"><input name="type" type="submit" value="Add Images"/></div></td>
                <td><div align="left"><input name="type" type="submit" value="View Location Finds"/></div></td>
            </tr>
        </table>
    </form><?php
}
于 2012-06-27T12:24:17.123 回答