without seeing your code it is difficult to determine what you are doing wrong.
Ignoring the code checking the stock quantity for the time being, get your page working with the 'add to cart' button enabled / disabled functionality.
to do this, create a php variable and give it a value > 0
then create a php if statement, something like...
<?php
if (php variable == 0) { ?>
**code for disabled button**
<?php
}
else {
?>
**code for normal button**
<?php
} ?>
this should give you a page with the 'add to cart' button enabled.
Try changing your php variable to 0, this should give you the 'add to cart' button disabled.
when you get this working ok, replace the php variable with the code that compares the cart quantity against the stock quantity