我想知道是否有人可以帮助我。
我正在使用下面的代码部分来创建一个正确列出与current user
相关的记录的表。
/* display row for each user */
echo "<tr>\n";
$theID = $row['locationid'];
echo " <td style='text-align: Center'>{$row['locationname']}</td>\n";
echo " <td style='text-align: Left'>{$row['returnedaddress']}</td>\n";
echo " <td style='text-align: Center'>{$row['totalfinds']}</td>\n";
echo " <form action= locationsaction.php method= 'post'><input type='hidden' name='lid' value=$theID/> <td><input type= 'submit' name= 'type' value= 'Details'/></td>
<td><input type= 'submit' name= 'type' value= 'Images'/></td>
<td><input type= 'submit' name= 'type' value= 'Add Finds'/></td>
<td><input type= 'submit' name= 'type' value= 'View Finds'/></td>
<td><input type= 'submit' name = 'type' value= 'Delete'/></td></form>\n";
在每个表格行的末尾有一系列按钮,通过下面显示的locatiosnaction.php
,将用户导航到其他页面,所有这些按钮都链接回主表记录。
'locationsaction.php'
<?php
session_start();
$_SESSION['lid'] = $_POST['lid'];
if (isset($_POST['type'])) {
$urls = array(
'Details' => 'viewlocation.php',
'Add Finds' => 'addfinds.php',
'Images' => 'addimages.php',
'View Finds' => 'locationfinds.php',
'Delete' => 'deletelocation.php'
);
$url = $urls[$_POST['type']];
header("Location: " . $url);
}
?>
我遇到的问题围绕着删除记录。这是我正在使用的查询:
'deletelocation.php'
<?php
$lid = $_SESSION['lid'];
$query = "DELETE FROM detectinglocations WHERE locationid='$lid'";
$result = mysql_query($query);
?>
按钮的功能正常,因为它将用户带到deletelocation.php脚本,但它不会删除记录。
我一直在使用几个脚本作为参考,我以为我会正确地遵循它们,但显然不是。
我只是想知道是否有人可以看看这个请让我知道我哪里出错了。
非常感谢和亲切的问候
答案 0 :(得分:4)
您错过了session_start();
开头的deletelocation.php
。
你必须在每个想要使用会话的页面上调用它。
因此,在您的情况下,$_SESSION['lid']
无法解析,这将使您的SQL查询无效。
session_start()创建会话或恢复当前会话 ...