php Isset 表达式错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23205968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:34:11  来源:igfitidea点击:

Isset expression error

phpisset

提问by user3411002

I have basically coded a code which populates a list of categories from my database then you are able to select which to delete.

我基本上编写了一个代码,该代码从我的数据库中填充类别列表,然后您就可以选择要删除的类别。

I have the issue with the delete code which does not seem to work due to the error:

我有删除代码的问题,由于错误,它似乎不起作用:

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in F:\xamppnew\htdocs0032\admin\delete.php on line 6

The line causing this is:

导致这种情况的行是:

if(isset($_POST['delete_id'] && !empty($_POST['delete_id']))) {

deletecategory.php

删除类别.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

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

回答by Jason OOO

You missed this ):

你错过了这个)

if(isset($_POST['delete_id']) && !empty($_POST['delete_id']))
                            ^---

回答by AbraCadaver

Others have shown the issue of the missing )in the expression, but empty()will check isset()so that is redundant. Just check empty():

其他人已经显示了)表达式中缺少的问题,但empty()会检查isset()它是多余的。只需检查empty()

if(!empty($_POST['delete_id'])) {

回答by dave

The issue is that this

问题是这

if(isset($_POST['delete_id'] && !empty($_POST['delete_id'])))

should be

应该

if(isset($_POST['delete_id']) && !empty($_POST['delete_id']))