0

我正在尝试制作一个用户照片删除脚本,用户可以删除自己的照片。问题是我希望用户确认,所以我在脚本中使用 $_GET 进行了确认。我不想当用户按下 Delete 键时,“Do you really want to blabla”这句话只出现在屏幕上。现在它只是在删除按钮和图像之后。

脚本:

if(($_GET['delete'] == '') || ($_GET['yes'] == '')) {
    if($numrows != 0){
        foreach ($result as $row) {

             echo '
                        <div class="imgwrapklein">
                                        '.$row['caption'].'<br />
                                        <a href="show.php?photo='.$row['id'].'" title="'.$row['caption'].'"><img src="'.$row['location'].'" alt="'.$row['beschrijving'].'" /></a><br />
                                        <a href="?delete='.$row['id'].'">Delete</a>
                                    </div>
                ';
        }   
    }else{
        echo 'There are no pics!';
    }
}else{
    echo 'Something went wrong!';
}

if($_GET['delete'] != ''){
    echo 'Are you sure you want to delete the picture <a href="?yes='.$_GET['delete'].'">Yes</a> - <a href="user-photo.php">No</a>';
}

if($_GET['yes'] != ''){
    // hier komt het verwijder gedeelte
}
4

3 回答 3

0

据我所知,null 不等于 '' ...

所以试试

if( isset($_GET['delete']) && ( $_GET['delete'] != '') ){
    echo 'Are you sure you want to delete the picture <a href="?yes='.$_GET['delete'].'">Yes</a> - <a href="user-photo.php">No</a>';
}
于 2013-08-28T08:42:32.827 回答
0

在您的情况下,最好的方法是让我们使用 Javascript confirm() 来验证操作。像这样(使用jquery):

$('form').submit(function () {
    if (confirm('do you really want to delete photo?')) {
        return true;
    } else {
        return false;
    }
});

如果您更喜欢使用 PHP,则必须制作另一个表单来确认用户想要删除照片的事实。

于 2013-08-28T08:42:40.263 回答
0

尝试了更多的东西,用php找到了这种方式:

if( isset($_GET['delete']) && ( $_GET['delete'] != '') ){
    echo 'Are you sure you want to delete the picture <a href="?yes='.$_GET['delete'].'">Yes</a> - <a href="user-photo.php">No</a>';
}else if( isset($_GET['yes']) && ( $_GET['yes'] != '' ) ){
    // hier komt het verwijder gedeelte
}else{
    if($numrows != 0){
        foreach ($result as $row) {

             echo '
                        <div class="imgwrapklein">
                                        '.$row['caption'].'<br />
                                        <a href="show.php?photo='.$row['id'].'" title="'.$row['caption'].'"><img src="'.$row['location'].'" alt="'.$row['beschrijving'].'" /></a><br />
                                        <a href="?delete='.$row['id'].'">Delete</a>
                                    </div>
                ';
        }   
    }else{
        echo 'There are no images!';
    }
}
于 2013-08-28T09:01:05.697 回答