0

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

Edited by Tenaciousmug: n/a

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by andy1090
0
$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);
}
0

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

0
<?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 ;
This topic has been dead for over six months. 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.