<?php
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "+")
{
$equals = $_POST['first'] + $_POST['second'];
}
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "-")
{
$equals = $_POST['first'] - $_POST['second'];
}
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "*")
{
$equals = $_POST['first'] * $_POST['second'];
}
if (isset($_POST['first']) && isset($_POST['second']) && isset($_POST['submit']) && $_POST['DDL'] == "/")
{
$equals = $_POST['first'] / $_POST['second'];
}
print $_POST['DDL']; // THIS IS THE LINE THAT RESULTS IN THE ERROR! WHY?
?>
<html>
<body>
<form method="post">
<input type="text" name="first">
<select name="DDL">
<option value="+" selected="selected">+</option>
<option value="-">-</option>b
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" name="second">
<input type="submit" name="submit" value="Equals">
<input type="text" name="equals" value="<?php if (!empty($equals)) print($equals) ?>">
</form>
</body>
</html>
The previous code results in the following error when accessing the index.php file BEFORE SUBMITTING THE FORM:
The php code "print $_POST[‘DDL’];" is causing the error.
Why is this happening?
I’ve already chosen a default value by using "+"…

When you first visit the page, you don’t have any post data.
This fires the exception you’re getting.
you should check the $_POST value / existence before processing the form data.
Hope this helps 🙂