0

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.

https://gist.github.com/anonymous/67f92c6d5f3ea1cde68a

1 Answer 1

2

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"]);
}
3
  • I am still getting an undefined index on line 11 of the controller.
    – sousheel
    Aug 5, 2014 at 16:39
  • I have updated the answer with additional info. Also try var_dump($_POST) and var_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
  • @user1723 Please open a new question and I will try to answer. Aug 5, 2014 at 19:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .