I have this code which is like a double or nothing game... And if its heads an option comes up (a button) to take your winnings, -or the original button which will bet again... The problem is, The second button resets the whole form, -and does not update values/execute php... Can anyone suggest a fix to this? or how i can get this working? <form id="form1" name="form1" method="post" action=""> <input type="submit" name="Submit" id="Submit" value="Play" /> </form> <? if (isset($_POST['Submit'])) { echo "You pay the man $10 and watch as he flips the coin..." ."<br>"; $coin = (rand()%2); if ($coin == 0) { echo "It lands on heads," . "<br>"; $bet = $bet * 2; echo "You are now betting $". $bet ."<br>"; mysql_query("UPDATE Doubleornothing SET Money = '$bet' WHERE Username = '$username'"); ?> <form id="form2" name="form2" method="post" action=""> <input type="submit" name="Submit2" id="Submit2" value="Take winnings" /> </form> <? if (isset($_POST['Submit2'])) { echo "You take your $". $bet; mysql_query("UPDATE Zombie SET Money = Money '$bet' WHERE Username = '$username'"); mysql_query("UPDATE Doubleornothing SET Money = '10' WHERE Username = '$username'"); } } if ($coin == 1) { echo "It lands on tails," . "<br>"; echo "You lose everthing..." . "<br>"; mysql_query("UPDATE Doubleornothing SET Money = '10' WHERE Username = '$username'"); } } Thanks alot, James
It should be something like this <? if ($_POST['action'] == "Play") { echo "You pay the man $10 and watch as he flips the coin..." ."<br>"; $coin = (rand()%2); if ($coin == 0) { echo "It lands on heads," . "<br>"; $bet = $bet * 2; echo "You are now betting $". $bet ."<br>"; mysql_query("UPDATE Doubleornothing SET Money = '$bet' WHERE Username = '$username'"); } if ($coin == 1) { echo "It lands on tails," . "<br>"; echo "You lose everthing..." . "<br>"; mysql_query("UPDATE Doubleornothing SET Money = '10' WHERE Username = '$username'"); } } if ($_POST['action'] == "Take winnings"){ echo "You take your $". $bet; mysql_query("UPDATE Zombie SET Money = Money '$bet' WHERE Username = '$username'"); mysql_query("UPDATE Doubleornothing SET Money = '10' WHERE Username = '$username'"); } ?> <form id="form1" name="form1" method="post" action=""> <input type="submit" name="action" id="Submit" value="Play" /> <input type="submit" name="action" id="Submit2" value="Take winnings" /> </form> Code (markup):
I think you have to put form action. Also check the update query. mysql_query("UPDATE Zombie SET Money = Money '$bet' WHERE Username = '$username'"); PHP: It should be like this mysql_query("UPDATE Zombie SET Money = '$bet' WHERE Username = '$username'"); PHP:
It sort off works, I want it so the Play button is before the game text, -and the 'Take winnings' button only appears after there is some winnings -on mine, after one heads. Anyone suggestions?
Try this <? <form id="form1" name="form1" method="post" action=""> if ($_POST['action'] == "Play") { echo '<input type="submit" name="action" id="Submit" value="Play" />'; echo "You pay the man $10 and watch as he flips the coin..." ."<br>"; $coin = (rand()%2); if ($coin == 0) { echo "It lands on heads," . "<br>"; $bet = $bet * 2; echo "You are now betting $". $bet ."<br>"; mysql_query("UPDATE Doubleornothing SET Money = '$bet' WHERE Username = '$username'"); } if ($coin == 1) { echo "It lands on tails," . "<br>"; echo "You lose everthing..." . "<br>"; mysql_query("UPDATE Doubleornothing SET Money = '10' WHERE Username = '$username'"); } } if ($_POST['action'] == "Take winnings"){ echo "You take your $". $bet; mysql_query("UPDATE Zombie SET Money = Money '$bet' WHERE Username = '$username'"); mysql_query("UPDATE Doubleornothing SET Money = '10' WHERE Username = '$username'"); } ?> <? if ($bet > 0) { ?> <input type="submit" name="action" id="Submit2" value="Take winnings" /> <? } ?> </form> Code (markup):