0

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...

4
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by EverWebby
0

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.

0

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:

0

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

Try this:

$sql = "UPDATE `Member` SET `rp` = rp+$winnings WHERE `username` = '$username'";
0

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?

0

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 (:

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.