Jump to content

Form Button leading to PHP code


Tenaciousmug

Recommended Posts

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"); ?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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);
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.