Going through the code....
$lotterySQL = sprintf("SELECT * FROM `lottery` WHERE `userID` = %d",
abs((int)$userid));
Is wrong. In the table created its set as userid. Not userID so you will need to change that query.
In the cron file at the bottom where the winner is credited the money.
There is no query its just a sprintf
so either make that line a query
$creditSQL = mysql_query(sprintf(
or add underneath that line
mysql_query($creditSQL);
and it will now credit the winner.
Feky's version is nicer with the form option for buying more tickets at once.