Undefined array key in php

Viewed 24

I can't define existing button in php although it exists. It gives me an error: Undefined array key "delete". Here's my html code:

<form action="receive.php" method="post">
    <button type="submit" id="delete-product-btn" class="rightBTN" name="delete">MASS DELETE</button>
</form>

And here's my php code:

<?php
    $delete = $_POST['delete'];
?>

I don't know why it won't work. Is there a typo or something that I don't know about.

1 Answers

If the system cannot find the correct value for assigning to a variable, then it will prompt warnings like Undefined xxxx "variable_name" in xxxxx

Hence, please use isset to check whether the $_POST values exist when they are assigned to the variables

Change

<?php
    $delete = $_POST['delete'];
?>

to

<?php
  if (isset($_POST['delete'])) {
  $delete = $_POST['delete'];
}
?>
Related