Need Help!! Beginner Programmer!

I need help with this game I am trying to make. It’s super simple but I can’t get the $money variable to change when the user rolls a 7 or doesn’t roll a 7. Please help, it’s getting quite frustrating. Here’s the code:
[php]

Craps

Craps Game

<?php $rollNum++; $firstDie = rand(1,6); $secondDie = rand(1,6);

print " ";
print “
”;
print “The object of the game is to double your money.

If you roll a 7 or 11 you gain 2 dollars, if not you lose a buck.

GOOD LUCK

”;
print <<<HERE



HERE;
if ($rollNum == 1){
print “
First Roll
”;
}
if ($rollNum != 1){
print “
Not First Roll
”;
}
$yourRoll = $firstDie + $secondDie;
if(!$money){
$money = 10;
}
$payoff = 0;

print “You rolled a $yourRoll
”;
if($yourRoll == 7){
$payoff =2;
$money += $payroll;
}
if ($yourRoll != 7){
$payoff = 1;
$money += $payroll;
}

if($money == 3){
print “Only 3 BUCKS! You better start getting lucky or you’ll lose soon”;
}
if ($money == 0){
print “Sorry you LOSE”;
$money = 10;
}
if ($money == 20){
print “You’ve WON! Great Job”;
$money = 10;
}$money += payoff;
print “Payoff is $payoff
\n”;
print “You have $money Dollars”;
print <<<HERE

HERE;
?>

[/php] [b]The Link to the Game is:[/b] http://ethnicfashionaspire.com/bookstuff/funCode/funCode6.php

This code will work if you have register_globals turned On in your php.ini (but this is deprecated).
Add this line, as indicated below:
[php]

<?php $money = $_REQUEST['money']; // ... the rest of your code[/php]

Thanks for your help but for some reason it’s still not working? I already had my globals on and I added the code? I also would like tips on the best resources to learn php? Thanks again

Here are couple of bugs in your code:
[php]$money += $payroll;[/php]

There are two instances of this code, but where is $payroll variable defined? Did you mean $payoff.

Also, in this line you are missing $ sign:
[php]}$money += payoff;[/php]

As for best resource to learn PHP, I find the best is PHP functions reference. Also, if you scroll down for each function there is a discussion, where you can find code examples and tips.

Wow I had a slow moment! Thanks a lot, I knew it was a simple mistake.

Sponsor our Newsletter | Privacy Policy | Terms of Service