Hi Chinmay,
I would recommend turning on error reporting within PHP - it gives you quite a lot of information about errors you are seeing. Add these two lines of PHP to the top of the scripts:
CODE
error_reporting(E_ALL);
ini_set("display_errors", 1);
I did that and ran your script and immediately saw the following notice:
CODE
Notice: Undefined variable: stock in test.php on line 5
That will help you to debug your application.
Jonathan LeBlanc
Senior Software Engineer
Yahoo! Developer Network
Twitter:
jcleblanc