Reading POST data
suggest changeData from a POST request is stored in the superglobal $_POST in the form of an associative array.
Accessing a missing key is Warning: Undefined array key since PHP 8.0, and was a Notice before that. isset() and ?? do not warn. empty() does not warn either, but it treats "0" as empty.
Example:
$from = isset($_POST["name"]) ? $_POST["name"] : "NO NAME";
$message = isset($_POST["message"]) ? $_POST["message"] : "NO MESSAGE";
echo "Message from $from: $message";
$from = $_POST["name"] ?? "NO NAME";
$message = $_POST["message"] ?? "NO MESSAGE";
echo "Message from $from: $message";
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents