Jump to content
MakeWebGames

Show Jackpot


Naffer20

Recommended Posts

Hi, I'm currently using this lottery mod. It works perfectly but the only problem is on the lottery.php it doesn't show the Jackpot it just shows the price of the ticket

Can someone help so it will show jackpot amount, thanks. :D

 

<?php

include "globals.php";

switch($_GET['action'])
{
  case 'buysub': buy_sub(); break;
  default: index(); break;
}


function index()
{
  global $db,$ir,$userid;

  $cost = 1000;
  $tick = 100;

  $sql = sprintf("SELECT * FROM `lottery`");
  $query = $db->query($sql);
  $row = $db->fetch_row($query);

  echo sprintf(" 
<font color = 'red' size = '3' /><b /><br>
              Welcome to the Mafia State Jackpot. 
<br>You currently have %d tickets
              and are able to purchase up to %d tickets per week.<br>
              Each ticket costs $cost. 
<br>The jackpot is %u.", $ir['lottery'], $tick,
              $cost,  $row['jackpot']);

  echo " 

        <form action = 'lottery.php?action=buysub' method = 'post' />
        <input type = 'text' STYLE='color: black; name = 'buysub' value = '1' /> 


        <input type = 'submit' STYLE='color: black; value = 'Buy Tickets' /> </form>";
}


function buy_sub()
{
  global $db,$ir,$userid;

  $_POST['buysub'] = abs((int) $_POST['buysub']);
  $cost = 1000;
  $price = $cost * $_POST['buysub'];

  if($_POST['buysub'] > 100)
  {
     die("You can't buy more than 100 lottery tickets. <a href = 'index.php' />Go Home</a>");
  }

  if($ir['lottery'] >= 100)
  {
     die("You have already purchased 100 tickets this week. <a href = 'index.php' />Go Home</a>");
  }

  if($_POST['buysub'] + $ir['lottery'] > 100)
  {
     die("You can't buy this many tickets because you would exceed the maximum amount of allowed tickets. <a href = 'index.php' />Go Home</a>");
  }

  if($ir['money'] < $price)
  {
     die("You don't have enough money to buy {$_POST['buysub']} tickets. <a href = 'index.php' />Go Home</a>");
  }

  else
  {
     print "You have bought {$_POST['buysub']} lottery tickets. <a href = 'index.php' />Go Home</a>";

     $sql = sprintf("UPDATE `users` SET `lottery` = `lottery` + '%d',
                 `money` = `money` - '%d'
                 WHERE `userid` = ('%u')",
                 $_POST['buysub'], $price, $userid);

     $db->query($sql);


     $sql1 = sprintf("INSERT INTO `lottery` (id,userid, amount) VALUES (%d,%u, %d)",
                  '',$userid, $price);

     $db->query($sql1);


     $sql2 = sprintf("UPDATE `lottery` SET `jackpot` = `jackpot` + '%d'",
                  $price);

     $db->query($sql2);
  }
}


$h->endpage();
?>
Link to comment
Share on other sites

Hi, I'm currently using this lottery mod. It works perfectly but the only problem is on the lottery.php it doesn't show the Jackpot it just shows the price of the ticket

Can someone help so it will show jackpot amount, thanks. :D

 

<?php

include "globals.php";

switch($_GET['action'])
{
  case 'buysub': buy_sub(); break;
  default: index(); break;
}


function index()
{
  global $db,$ir,$userid;

  $cost = 1000;
  $tick = 100;

  $sql = sprintf("SELECT * FROM `lottery`");
  $query = $db->query($sql);
  $row = $db->fetch_row($query);

  echo sprintf(" 
<font color = 'red' size = '3' /><b /><br>
              Welcome to the Mafia State Jackpot. 
<br>You currently have %d tickets
              and are able to purchase up to %d tickets per week.<br>
              Each ticket costs $cost. 
<br>The jackpot is %u.", $ir['lottery'], $tick,
              $cost,  $row['jackpot']);

  echo " 

        <form action = 'lottery.php?action=buysub' method = 'post' />
        <input type = 'text' STYLE='color: black; name = 'buysub' value = '1' /> 


        <input type = 'submit' STYLE='color: black; value = 'Buy Tickets' /> </form>";
}


function buy_sub()
{
  global $db,$ir,$userid;

  $_POST['buysub'] = abs((int) $_POST['buysub']);
  $cost = 1000;
  $price = $cost * $_POST['buysub'];

  if($_POST['buysub'] > 100)
  {
     die("You can't buy more than 100 lottery tickets. <a href = 'index.php' />Go Home</a>");
  }

  if($ir['lottery'] >= 100)
  {
     die("You have already purchased 100 tickets this week. <a href = 'index.php' />Go Home</a>");
  }

  if($_POST['buysub'] + $ir['lottery'] > 100)
  {
     die("You can't buy this many tickets because you would exceed the maximum amount of allowed tickets. <a href = 'index.php' />Go Home</a>");
  }

  if($ir['money'] < $price)
  {
     die("You don't have enough money to buy {$_POST['buysub']} tickets. <a href = 'index.php' />Go Home</a>");
  }

  else
  {
     print "You have bought {$_POST['buysub']} lottery tickets. <a href = 'index.php' />Go Home</a>";

     $sql = sprintf("UPDATE `users` SET `lottery` = `lottery` + '%d',
                 `money` = `money` - '%d'
                 WHERE `userid` = ('%u')",
                 $_POST['buysub'], $price, $userid);

     $db->query($sql);


     $sql1 = sprintf("INSERT INTO `lottery` (id,userid, amount) VALUES (%d,%u, %d)",
                  '',$userid, $price);

     $db->query($sql1);


     $sql2 = sprintf("UPDATE `lottery` SET `jackpot` = `jackpot` + '%d'",
                  $price);

     $db->query($sql2);
  }
}


$h->endpage();
?>

 

  • No need for sprintf on line 19.
  • Line 24, you're either trying to end a b tag (incorrectly) or doing a line break (incorrectly)
  • Inline styles are 'frowned upon'
  • Avoid die to show error messages relating to the modification, echo and $h->endpage w/ exit; will suffice, and look more professional with a finished layout
  • Check to see if $_POST['buysub'] isn't 0 before doing the math (line 48)
  • No need for the `id` column in the query (line 82)

 

Now to your query;

  • Is the column name from `lottery` called `jackpot`?
  • Have you tried var_dump($row);?
  • Have you echo'd it out of the sprintf function?
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...