Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isset expression error

Tags:

php

isset

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\htdocs\650032\admin\delete.php on line 6

The line causing this is:

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';
      }
    }
    ?>
like image 302
user3411002 Avatar asked Apr 21 '14 21:04

user3411002


People also ask

What is an isset () function?

Definition and Usage The isset() function checks whether a variable is set, which means that it has to be declared and is not NULL. This function returns true if the variable exists and is not NULL, otherwise it returns false.

What is isset ($_ GET in PHP?

The isset() function is an inbuilt function in PHP which checks whether a variable is set and is not NULL. This function also checks if a declared variable, array or array key has null value, if it does, isset() returns false, it returns true in all other possible cases.

What can I use instead of isset in PHP?

The equivalent of isset($var) for a function return value is func() === null . isset basically does a !== null comparison, without throwing an error if the tested variable does not exist.

How do I find the Isset?

Answer: Use the PHP isset() function You can use the PHP isset() function to test whether a variable is set or not. The isset() will return FALSE if testing a variable that has been set to NULL .


1 Answers

You missed this ):

if(isset($_POST['delete_id']) && !empty($_POST['delete_id']))
                            ^---
like image 194
Jason OOO Avatar answered Sep 19 '22 23:09

Jason OOO