I am having a problem with the 'undefined index' in sell. I think it is because I don't know what the drop-down menu and submit button will return, and what that variable name will be.
1 Answer
The menu
value is not being correctly assigned in the HTML page. The name of the variable needs to be on the element that you want to access.
In your code, the menu
variable name is assigned to the form
element.
<form name="menu" action="sell.php" method="POST">
It should be assigned to the <select>
tag, since that is the value you want.
<select name="menu">
Another problem is that the first time the sell controller loads, the menu will not have been selected, and so the value of menu
will be undefined. You can use the empty() function to check if the menu
variable has a value:
if (!empty($_POST["menu"])) {
query("DELETE FROM Stock WHERE id = ? AND symbol = ?", $_SESSION["id"], $_POST["menu"]);
}
-
-
I have updated the answer with additional info. Also try
var_dump($_POST)
andvar_dump($_SESSION)
to inspect the variables being passed to the controller, to ensure that they contain the expected values. Aug 5, 2014 at 17:38 -