Hi first let me tell you I’m posting a “summary” of my code here NOT because I havent tried solving my issue or I’m lazy. Because of my little knowledge on PHP struggling to crack the error now for 3.5hrs!
So im much grateful if someone can point out why this error is happening. The error says undefined error in line 4.
<?php
function validate(&$x,&$y)
{if(isset($_POST['sub1']))
{if($_POST['optMe'] == "") {echo "Empty dropdown"; return false;}}
}
function display($x,$y)
{
?>
<html>
<head><title></title></head>
<body>
<form method="POST">
<table id="tab2" border="1">
<tr><td>
<select id="optMe">
<option value=""></option>
<option value="one">one</option>
<option value="two">two</option>
</select>
</td>
<td><input type="submit" id="sub1" name="sub1" value="Click here"></td>
</tr>
</table>
</form>
<form method="POST">
<table id="tab2" border="1">
<tr>
<td><input type="text"></td>
<td><input type="submit" id="send" name="send" value="send now"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
function process($x)
{
// I will add my code here to print something.
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{$formValues = $_POST;$formErrors = array();
if (!validate($formValues, $formErrors))
display($formValues, $formErrors);
else
process($formValues);
}
else
display(null, null);
?>
Your
<select>has nonameattribute, so it doesn’t get sent, so$_POST['optMe']doesn’t exist, so you get an error.