我已經基本編碼了一個代碼,它填充了我的數據庫中的類別列表,然後您可以選擇要刪除的類別。Isset表達式錯誤
我有刪除代碼的問題,它似乎並沒有工作,由於錯誤:
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in F:\xamppnew\htdocs\650032\admin\delete.php on line 6
線造成這樣的:
if(isset($_POST['delete_id'] && !empty($_POST['delete_id']))) {
deletecategory.php
<h3>
Delete Category
</h3>
<?php $result = mysql_query("SELECT * FROM category"); ?>
<table>
<?php while($row = mysql_fetch_array($result)) : ?>
<tr id="<?php echo $row['category_id']; ?>">
<td><?php echo $row['category_Name']; ?></td>
<td>
<button class="del_btn" rel="<?php echo $row['id']; ?>">Delete</button>
</td>
</tr>
<?php endwhile; ?>
</table>
<script>
$(document).ready(function(){
$('.del_btn').click(function(){
var del_id = $(this).attr('rel');
$.post('delete.php', {delete_id:del_id}, function(data) {
if(data == 'true') {
$('#'+del_id).remove();
} else {
alert('Could not delete!');
}
});
});
});
</script>
delete.php
<?php
if(isset($_POST['delete_id'] && !empty($_POST['delete_id']))) {
$delete_id = mysql_real_escape_string($_POST['delete_id']);
$result = mysql_query("DELETE FROM category WHERE `id`=".$delete_id);
if($result !== false) {
echo 'true';
}
}
?>
您的代碼容易受到SQL注入。 ['mysql_real_escape_string'只在MySQL字符串文字中使用該值時才起作用。](http://security.stackexchange.com/a/35718/539) – Gumbo
沒有必要使用'isset()'和' !空()'在同一時間。如果輸入沒有定義,'empty'也可以工作:https://stackoverflow.com/questions/4559925/why-check-both-isset-and-empty – Adam