2013-08-28 72 views
0

我想使用戶照片刪除腳本,用戶可以刪除自己的照片。 問題是我想讓用戶確認,所以我在$ _GET中做了腳本。我不想當用戶按下刪除時,只有在屏幕上顯示「你真的想要說什麼」這句話。現在它只是在刪除按鈕和圖像之後。卡住不顯示文本與GET

腳本:

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 
} 
+0

爲什麼不只是使用JavaScript來顯示確認對話框? – tborychowski

+0

@agree與tborychowski JavaScript是更簡單 – Parfait

+0

如果(確認(「你確定要刪除照片?」)){// 做一些 } – Parfait

回答

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!'; 
    } 
} 
0

空不等於 '' 據我知道...

所以儘量

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>'; 
} 
0

在你的情況下,最好的辦法是給我們使用Javascript confirm()來驗證操作。像這樣的(使用jQuery):

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

如果你喜歡使用PHP,你將不得不作出另一種形式來確認用戶想要刪除照片的事實。