943,187 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 396
  • PHP RSS
Jun 17th, 2010
0

Random Game PHP?

Expand Post »
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:

PHP Syntax (Toggle Plain Text)
  1. <p><?php
  2. $dice = rand(1,6);
  3. if($dice == 1){
  4. echo "You rolled a
  5. <br><b>1</b>";
  6. }if($dice == 2){
  7. echo "You rolled a
  8. <br><b>2</b>";
  9. }if($dice == 3){
  10. echo "You rolled a
  11. <br><b>3</b>";
  12. }if($dice == 4){
  13. echo "You rolled a
  14. <br><b>4</b>";
  15. }if($dice == 5){
  16. echo "You rolled a
  17. <br><b>5</b>";
  18. }if($dice == 6){
  19. echo "You rolled a
  20. <br><b>6</b>";
  21. }
  22.  
  23. $winner = "500";
  24. if($dice == 6);
  25. {
  26. include("haha.php");
  27. $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
  28. $sql = "INSERT INTO Member (rp) VALUES ('$winner')";
  29. mysqli_query($cxn,$sql);
  30. }
  31. ?>
Last edited by Tenaciousmug; Jun 17th, 2010 at 2:48 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
Tenaciousmug is offline Offline
46 posts
since Jun 2010
Jun 18th, 2010
0
Re: Random Game PHP?
PHP Syntax (Toggle Plain Text)
  1. $dice = mt_rand(1,6);
  2. echo "You rolled a <br /><strong>$dice</strong>";
  3. if($dice == 6){
  4. include("haha.php");
  5. $cxn = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbdatabase);
  6. //assume logged in member id = 67
  7. $sql = "INSERT INTO Member SET rp = rp + 500 WHERE member_id = 67";
  8. mysqli_query($cxn,$sql);
  9. }
Sponsor
Featured Poster
Reputation Points: 1041
Solved Threads: 935
Sarcastic Poster
ardav is offline Offline
6,624 posts
since Oct 2006
Jul 28th, 2010
0
Re: Random Game PHP?
This isnt working either. I dont get it.. its probably something so simple.
Reputation Points: 10
Solved Threads: 1
Light Poster
Tenaciousmug is offline Offline
46 posts
since Jun 2010
Aug 8th, 2010
0

testing out a user combo

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. include("head.php");
  4. $db_host = 'HOST';
  5. $db_user = 'USERNAME';
  6. $db_pass = 'PASSWORD';
  7. $db = 'DB USERNAME';
  8.  
  9. $dice = rand(1,6);
  10. if($dice == 1){
  11. echo "You rolled a
  12. <br><b>1</b>";
  13. }if($dice == 2){
  14. echo "You rolled a
  15. <br><b>2</b>";
  16. }if($dice == 3){
  17. echo "You rolled a
  18. <br><b>3</b>";
  19. }if($dice == 4){
  20. echo "You rolled a
  21. <br><b>4</b>";
  22. }if($dice == 5){
  23. echo "You rolled a
  24. <br><b>5</b>";
  25. }if($dice == 6){
  26. echo "You rolled a
  27. <br><b>6</b>";
  28. }
  29.  
  30.  
  31. $winner = "500";
  32. if($dice == 6);
  33. {
  34. $cxn = mysqli_connect($db_host,$db_user,$db_pass,$db);
  35. $sql = "INSERT INTO Member (rp) VALUES ('$winner')";
  36. mysqli_query($cxn,$sql);
  37. }
  38. ?>
  39.  
  40. -- --------------------------------------------------------
  41.  
  42. --
  43. -- Table structure for table `Member`
  44. --
  45.  
  46. CREATE TABLE `Member` (
  47. `member_ID` int(123) NOT NULL auto_increment,
  48. `username` varchar(30) NOT NULL,
  49. `password` varchar(30) NOT NULL,
  50. `rp` varchar(5) NOT NULL,
  51. `ip` varchar(30) NOT NULL,
  52. PRIMARY KEY (`member_ID`),
  53. UNIQUE KEY `username` (`username`),
  54. KEY `password` (`password`,`rp`)
  55. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andy1090 is offline Offline
1 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: php runs a 3d object flashMovie?
Next Thread in PHP Forum Timeline: convert integer number to float number





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC