Ok I don't understand why the update statement only works once.. and after it rolls another 6, it wont add another 500 to the RP amount.

<?php
session_start();
include("logincheck.php");
?>
<?php include_once("header.php"); ?>
<td width='100%' valign='top' align='center'>
<center><?php
$dice = rand(1,6);
echo "You rolled a<br /><b>{$dice}</b>\n";

if($dice == 6)
{
    include("haha.php");
    $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
    $winnings = "500";
    $username = $_SESSION['username'];
    $sql = "UPDATE `Member` SET `rp` = 'rp' + '$winnings' WHERE `username` = '$username'";
    mysqli_query($cxn,$sql);
}
?></center>
</td></p>
<?php include_once("footer.php"); ?>

Can anyone figure out why? I mean it works one time...

You don't have a loop so it makes sense that it would only execute once when $dice is equal to 6. If your intent is to keep generating random values and showing what was rolled, you need a While loop and you will need to change your code to put any one-time actions (like the mysqli) before you start the loop.

You don't have a loop so it makes sense that it would only execute once when $dice is equal to 6. If your intent is to keep generating random values and showing what was rolled, you need a While loop and you will need to change your code to put any one-time actions (like the mysqli) before you start the loop.

No I dont want them to roll until they roll a six. Its like a random game. They play 20 times a day. They roll 20 times to see if they can roll a six and every time they do, they get 500rp. The other times they just dont get anything.

And its still only generating once. Does anyone get what Im saying?? D:

The problem is that you are treating rp as a text value.

Try this:

$sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'";
Member Avatar for rajarajan2017

They roll 20 times to see if they can roll a six

How do you define this 20 times? your code only works on page refreshing, no loops are there. So how come its possible?

Im not sure on making it 20 times daily yet, but Im creating a database for the game and... nevermind. I already know how to make it 20 times daily.

EverWebby, you are the best!!!! ITS WORKING NOW (:

Glad to be of assistance

Make sure you clean your data and validate the username as some simple cracking will destroy your project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.