【问题标题】:Deleting and redirecting to the same page删除并重定向到同一页面
【发布时间】:2019-03-17 17:04:13
【问题描述】:

您好,我有这个删除功能,但我还没有设置任何功能,因为我想删除数据并在同一页面中重定向,但我不知道我是如何尝试研究的,但它不起作用.在此页面中,显示的所有信息都从一个页面发送到此页面,以便用户查看日程安排,然后可以选择删除它,但我不知道如何删除数据并重定向到同一页面而不会弄乱向上显示的其他数据..我尝试使用 header(location:) 函数但是当我重定向显示的数据时没有显示,因为我在重定向时没有传递任何值需要帮助,这是我的代码

if ($teacher<>""){
    $query1 = mysqli_query($conn," SELECT *  from schedule natural join instructor where day ='t' and schedule.instructorID ='$teacher' and timeID ='$id' and grade = '$grade' and semester = '$semester'");
}
elseif ($room<>""){
    $query1 = mysqli_query($conn,"SELECT * from schedule  natural join instructor where day = 't' and  schedule.room = '$room' and timeID ='$id' and grade = '$grade' and semester = '$semester'");
}
elseif ($strand<>""){
    $query1 = mysqli_query($conn,"SELECT * from schedule  natural join instructor where day = 't' and  schedule.strand= '$strand' and timeID ='$id' and grade = '$grade' and semester = '$semester'");
}
$row1 = mysqli_fetch_array($query1);
$id1 = $row['scheduleID'];
$count=mysqli_num_rows($query1);
if ($count==0)//checking
{
    //echo "<td></td>";

}
else
{
    //print 
    echo "<li class='showme'>"; 
    echo "<a href='#' id='$id1' class='delete' title='Delete'>Remove</a>";
    echo $row1['subject'];
    echo "</li>";
    echo "<li class='$displayc'>$row1[strand]</li>";
    echo "<li class='$displaym'>$row1[fname], $row1[lname]</li>";                                           
    echo "<li class='$displayr'>Room $row1[room]</li>";

    echo "</ul>";
    echo "</div>";
}   
?>
</td>

然后我有 delete.php 但我还没有任何设置函数,因为它我只知道如何使用表单删除,但是由于上述原因,当您删除时重定向是问题

【问题讨论】:

  • 在 PHP 中使用 &lt;&gt; 是非常罕见的。把我吓了一跳。
  • 请用代码解释更多
  • 上面显示的代码是在用户选择一个strand、room或teacher查看时显示数据。 @gaurav

标签: javascript php mysql


【解决方案1】:

重大安全漏洞:SQL Injection 使用prepared statements 进行查询

在您的标题位置,只需附加一个query string

查询字符串可以通过以下方式检索:

$grade = int($_GET['grade']);
$semester = int($_GET['semester']);

其中gradesemester 是参数名称。 请注意,出于卫生目的,$_GET[...] 已用 int(...) 包裹。这确保$gradesemester 将是“int”(数字)。

您的位置标头应如下所示: LOCATION: http://yoursite/diplay-page.php?grade=7&amp;semester=8

此外,在显示时,请转义您的数据!现在,您很容易受到XSS injections 的攻击。

如果您不知道怎么做,请从 OWASP 建议开始:https://www.owasp.org/index.php/PHP_Top_5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    相关资源
    最近更新 更多