Wow, I have no clue what I'm doing.. I'm trying to make a random game and if you roll a 6, you will win 500 rp and I'm trying to insert the 500 rp into the user who is logged in ($_SESSION['username'). But I... just don't know where to begin.

Here is my crappy coding that I just.. am stumped on:

<p><?php
$dice = rand(1,6);
if($dice == 1){
echo "You rolled a 
<br><b>1</b>";
}if($dice == 2){
echo "You rolled a
<br><b>2</b>";
}if($dice == 3){
echo "You rolled a
<br><b>3</b>";
}if($dice == 4){
echo "You rolled a
<br><b>4</b>";
}if($dice == 5){
echo "You rolled a
<br><b>5</b>";
}if($dice == 6){
echo "You rolled a
<br><b>6</b>";
}

$winner = "500";
if($dice == 6);
{
include("haha.php");
$cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
$sql = "INSERT INTO Member (rp) VALUES ('$winner')";
mysqli_query($cxn,$sql);
}
?>

Recommended Answers

All 3 Replies

Member Avatar for diafol
$dice = mt_rand(1,6);
echo "You rolled a <br /><strong>$dice</strong>";
if($dice == 6){
  include("haha.php");
  $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
  //assume logged in member id = 67
  $sql = "INSERT INTO Member SET rp = rp + 500 WHERE member_id = 67";
  mysqli_query($cxn,$sql);
}

This isnt working either. I dont get it.. its probably something so simple.

<?php

include("head.php");
$db_host = 'HOST';
$db_user = 'USERNAME';
$db_pass = 'PASSWORD';
$db = 'DB USERNAME';

$dice = rand(1,6);
if($dice == 1){
echo "You rolled a 
<br><b>1</b>";
}if($dice == 2){
echo "You rolled a
<br><b>2</b>";
}if($dice == 3){
echo "You rolled a
<br><b>3</b>";
}if($dice == 4){
echo "You rolled a
<br><b>4</b>";
}if($dice == 5){
echo "You rolled a
<br><b>5</b>";
}if($dice == 6){
echo "You rolled a
<br><b>6</b>";
}


$winner = "500";
if($dice == 6);
{
$cxn = mysqli_connect($db_host,$db_user,$db_pass,$db);
$sql = "INSERT INTO Member (rp) VALUES ('$winner')";
mysqli_query($cxn,$sql);
}
?>

-- --------------------------------------------------------

-- 
-- Table structure for table `Member`
-- 

CREATE TABLE `Member` (
  `member_ID` int(123) NOT NULL auto_increment,
  `username` varchar(30) NOT NULL,
  `password` varchar(30) NOT NULL,
  `rp` varchar(5) NOT NULL,
  `ip` varchar(30) NOT NULL,
  PRIMARY KEY  (`member_ID`),
  UNIQUE KEY `username` (`username`),
  KEY `password` (`password`,`rp`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
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.