Tenaciousmug Posted September 19, 2010 Share Posted September 19, 2010 Ok my question is, when they hit the "Play!" button, then I want the php code below to pop up. Like... i think I would use the GET method, but I'm not sure still. I don't think that really matters what method you use, but how do I say IF they click on the "Play" button, then lead them to this code so they can start playing the game. I'm entering this into the database, but I'm just trying to get this code first. I already know how to make it lead to the database and whatnot. <?php session_start(); include("logincheck.php"); ?> <?php include_once("header.php"); ?> <br> Welcome to the Six Dice game. <br><br><b>Instructions</b>: You play this game by randomly rolling a dice. If you land on 1-5, you earn 0 rp. If you land on a 6, you earn 500rp! The game is free so why not give it a shot? <br>You may only play this game 25 times a day! <br><br><form action="sixdice.php?roll" method="post"> <input type="submit" name="playsix" value="Play!" /> </form> <?php if(isset($_POST['playsix'])); $dice = rand(1,6); echo "You rolled a<br /><b>{$dice}</b>\n"; $winnings = "500"; if($dice == 6) { include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $username = $cxn->real_escape_string($_SESSION['username']); $sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'"; mysqli_query($cxn,$sql); }?> <FORM ACTION="sixdice.php" METHOD="post"> <INPUT TYPE="submit" VALUE="Roll Again!" /> </FORM> <?php include_once("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/213809-form-button-leading-to-php-code/ Share on other sites More sharing options...
fortnox007 Posted September 19, 2010 Share Posted September 19, 2010 dont use $_GET to update a database, use get to retrieve (get) stuff. Btw: Doesn't your code already work? I might have missed something but this seems to already work. If not please tell in a more precise manner what you want. By the way the last part of your code isn't really nice: <FORM ACTION="sixdice.php" METHOD="post"> <INPUT TYPE="submit" VALUE="Roll Again!" /> </FORM> use lower case and don't forget a name for your submit button Quote Link to comment https://forums.phpfreaks.com/topic/213809-form-button-leading-to-php-code/#findComment-1112801 Share on other sites More sharing options...
Tenaciousmug Posted September 19, 2010 Author Share Posted September 19, 2010 yeah i know. a friend helped me with that part a long time ago and i never really changed it yeah for some reason, its just not working... it already displays the whole code. when i want when you hit the Play button, I want it to lead to a separate page.. like not one that is in the public_html, but with the funky URL. you know how it would say sixdice.php?roll and a whole lot of other junk. thats from the GET method, I know. even before the play button is hit to lead to that php code, it is already showing it underneath the play button. i want it to lead to separate page where they can start playing the game. i dont know how to explain myself. i mean i could give you alink to the page, but you have to register in order to view it because thats how i coded all the pages. Quote Link to comment https://forums.phpfreaks.com/topic/213809-form-button-leading-to-php-code/#findComment-1112809 Share on other sites More sharing options...
Tenaciousmug Posted September 20, 2010 Author Share Posted September 20, 2010 Can anyone help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/213809-form-button-leading-to-php-code/#findComment-1113037 Share on other sites More sharing options...
WatsonN Posted September 20, 2010 Share Posted September 20, 2010 <?php if(isset($_POST['playsix'])){ $dice = rand(1,6); echo "You rolled a<br /><b>{$dice}</b>\n"; $winnings = "500"; if($dice == 6){ include("haha.php"); $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase); $username = $cxn->real_escape_string($_SESSION['username']); $sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'"; mysqli_query($cxn,$sql); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/213809-form-button-leading-to-php-code/#findComment-1113043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.