Reading POST data

suggest change

Data 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";

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents