Welcome to PHPBuilder! When posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze.
As for your problem, you can't reference array items with a quoted string index/key (unless you use the 'complex syntax' - e.g. adding {} braces around the variable reference). See this manual page for more information/examples (specifically, take a look at the section following the text 'More examples to demonstrate this behaviour:').
EDIT: Also note that user-supplied data should never be placed directly into a SQL query string, else your code will be vulnerable to SQL injection attacks and/or just plain SQL errors. Instead, you must first sanitize the data with a function such as [man]mysql_real_escape_string/man (for string data) or use prepared statements.