i want to echo selected parent value. but i am getting error- Notice: Undefined index:
How can i echo selected parent value then? Whats wrong i am doing?
$q = mysql_query("SELECT * FROM menu");
echo '<form action="" method="post">
Menu name:<input type="text" name="mname"><br>
<select>';
while ($row = mysql_fetch_array($q)) {
$menu_name = $row['menu_name'];
echo '<option value="'.$menu_name.'">'.$menu_name.'</option>';
}
echo '</select><br>
<input type="submit" name="submit" value="Add Menu">
</form>';
if (isset($_POST['submit'])) {
echo $mname = $_POST['mname'];
echo $parent = $_POST[$menu_name];
}
mysql_query()andmysql_fetch_array()are deprecated, please usemysqli_query()andmysqli_fetch_array()in the future$_POST[$menu_name]?$menu_nameis only ever going to contain the LAST item you fetched from the db. And since your<select>has noname, it'll never get submitted with the rest of the form anyways.mysql_queryinterface. It’s so awful and dangerous that it was removed in PHP 7. A replacement like PDO is not hard to learn and a guide like PHP The Right Way explains best practices.