jfunchio 0 Light Poster

I need help using a mysql user defined function in php. What i want to do is use the mysql function to perform a query to get the count from the inventory table whose movie_id's are equal to the movie_id entered by the user. And then I would like to use the return value of that in a php if expression. The echo in the if statement is just to see if it's working. I'm new to php and mysql so i might be way off in how I'm going about doing it. Could someone please help me out.

<?php
  include_once("connection.php");

  $stock=readline("Enter movie_id: ");

  $db_obj->query( "create function check_stock($stock)
               returns integer
               begin
               declare d_count integer;
                  select count into d_count
                  from inventory
                  where movie.movie_id = '$stock'
               return d_count;
               end");

   $result = $db_obj->query("select check_stock($stock");
     if($result == 1)
     {
        echo "success\n";
     }
?>