Jump to content
MakeWebGames

[In Production] Brewery Mod


Recommended Posts

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

What do you mean by the variable?

Think of a variable like a box.

You put something into the box.

You write a name on the box.

Anytime you need what's in the box you go and find the box with that name.

in code:

// Put the string "item" into the box.
$box = "item";

// Get the string from the box
echo $box;

 

Have you dived into php without actually reading any tutorials or documentation on it?

Link to comment
Share on other sites

Think of a variable like a box.

You put something into the box.

You write a name on the box.

Anytime you need what's in the box you go and find the box with that name.

in code:

// Put the string "item" into the box.
$box = "item";

// Get the string from the box
echo $box;

 

Have you dived into php without actually reading any tutorials or documentation on it?

Thanks

And to be honest, I haven't watched any tutorials, I have just been learning from here, (yes I get help with some stuff) so yeah I really only know what I'm coding the in php, so not all that much, I will slowly learn, i have watched like three tutorials, but I find them confusing haha.

So I'm just going to teach myself

Edited by -BRAIDZ-
Link to comment
Share on other sites

Alright, I changed it so you have to collect the alcohol after it has been brewed, instead of automaticly being Credited the item, I also made it so the user can input the amount they want, but they can collect more than they are supposed to.

How can I fix this, so if they try get more than the amount they can actually collect, it comes up with an error message like "You don't have that much Beer" or something like that.

This is what I have done

function collect_beer() {

global $db, $ir, $c, $userid, $h;


print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Collect Beer</h3>";

echo "<form method='post' action='brewery.php?action=beercollected'>
Beer(s): <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='10' />
</br><input type='submit' name='beercollected' value='Collect' />
                               </form>";

}

function beer_collected() {

global $db, $ir, $c, $userid, $h, $_POST;
$_POST['brewed_beer']= abs((int) $_POST['brewed_beer']);
if($_POST['brewed_beer'] <= 0) {
echo "You don't have this much beer"; {
}
global $db, $ir, $c, $userid, $h;
if($ir['brewed_beer'] == 0) {

  echo 'You have no beer already brewed to collect, you better start brewing';
  $h->endpage();
  die;
}else{
echo "You have collected your beer";
$db->query("UPDATE users SET brewed_beer=brewed_beer - {$ir['brewed_beer']} WHERE userid=$userid");
item_add($userid, 277, ($_POST['amount']));

}
}
}
?>

 

Can anyone figure it out?

I don't want the style of my code changed either, because it will make it too difficult to keep going.

I know my coding is outdated, but that's the only way I know to code for now

Link to comment
Share on other sites

For one, your variable: $_POST['brewed_beer'] shouldn't exist, change that to $ir['brewed_beer'].

Now if you want to check whether they are trying to collect more:

if($_POST['amount'] > $ir['brewed_beer']){

// error

}

 

Also there is a difference between teaching yourself and asking everyone for the next step. Teaching yourself involves reading tutorials, articles and language documentation.

http://www.w3schools.com/php/default.asp

That has good tutorials on the basics of php, they are not videos.

Learning language is going to be complicated to start off with until you've done it a few times. Learning by asking everyone else what is wrong or what to do next is only going to get you so far, and your going to be constantly doing it

Link to comment
Share on other sites

[...]

Also there is a difference between teaching yourself and asking everyone for the next step. Teaching yourself involves reading tutorials, articles and language documentation.

http://www.w3schools.com/php/default.asp

That has good tutorials on the basics of php, they are not videos.

[...]

Errrm. Although they've got better, I'd still avoid them.

 

Link to comment
Share on other sites

For one, your variable: $_POST['brewed_beer'] shouldn't exist, change that to $ir['brewed_beer'].

Now if you want to check whether they are trying to collect more:

if($_POST['amount'] > $ir['brewed_beer']){

// error

}

 

Also there is a difference between teaching yourself and asking everyone for the next step. Teaching yourself involves reading tutorials, articles and language documentation.

http://www.w3schools.com/php/default.asp

That has good tutorials on the basics of php, they are not videos.

Learning language is going to be complicated to start off with until you've done it a few times. Learning by asking everyone else what is wrong or what to do next is only going to get you so far, and your going to be constantly doing it

Like this?

function collect_beer() {

global $db, $ir, $c, $userid, $h;


print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Collect Beer</h3>";

echo "<form method='post' action='brewery.php?action=beercollected'>
Beer(s): <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='10' />
</br><input type='submit' name='beercollected' value='Collect' />
                               </form>";

}

function beer_collected() {

global $db, $ir, $c, $userid, $h, $_POST;
$ir['brewed_beer']= abs((int) $ir['brewed_beer']);
if($_POST['amount'] > $ir['brewed_beer']){
echo "You don't have this much beer"; {
$h->endpage();
  die;
}else{
echo "You have collected your beer";
$db->query("UPDATE users SET brewed_beer=brewed_beer - {$ir['brewed_beer']} WHERE userid=$userid");
item_add($userid, 277, ($_POST['amount']));

}
}
}
?>

 

And yes, but I did try, and I tried numerous things and just couldn't work it out..

Link to comment
Share on other sites

Now when I input the number of Bottles of Beer I want to exchange, it truncates my function brewed_beer

<?php  
require_once("globals.php");

if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); }
if($ir['brew'] == 10) {
  echo 'You have already brewed 10 times today, come back tomorrow';
  $h->endpage();
  die;
}

$_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : '';
switch($_GET['action']){

       case 'beer': brew_beer(); break;
       case 'drinkbeer': drink_beer(); break;
       case 'brewbeer': brew_beer_sub(); break;
       case 'whiskey': brew_whiskey(); break;
       case 'collectbeer': collect_beer(); break;
       case 'beercollected': beer_collected(); break;
       default: brewery(); break;
}

function brewery() {
global $db,$ir,$c,$userid,$h;


  print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'> 
<table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table>

<h3>Your Brewery</h3>";

  echo "
You are sitting in your shed.
</br>What would you like to brew?</br>";

  echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'>Brewery Options</th>
</tr>
<tr>
<td>Beer</td>
<td> <a href='brewery.php?action=beer'>Brew</a> </td>
</tr>
<tr>
<td>Whiskey</td>
<td> <a href='brewery.php?action=whiskey'>Brew</a> </td>
</tr>
</tr>
<tr>
<td>Cider</td>
<td> <a href='brewery.php?action=cider'>Brew</a> </td>
</tr>
</tr>
<tr>
<td>Vodka</td>
<td> <a href='brewery.php?action=vodka'>Brew</a> </td>
</tr>
</table>
  ";

  echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'>Collection of Alcohol</th>
</tr>
<tr>
<td>Beer</td>
<td> <a href='brewery.php?action=collectbeer'>Collect</a> </td>
</tr>
<tr>
<td>Whiskey</td>
<td> <a href='brewery.php?action=whiskey'>Collect</a> </td>
</tr>
</tr>
<tr>
<td>Cider</td>
<td> <a href='brewery.php?action=cider'>Collect</a> </td>
</tr>
</tr>
<tr>
<td>Vodka</td>
<td> <a href='brewery.php?action=vodka'>Collect</a> </td>
</tr>
</table>
  ";

  print "<h3><font color='red'>This module is not complete and is still in the early stage of production.</br>
  Not all functions will work properly.</font></h3>";

}

function brew_beer() {
print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Beer</h3>";


  echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'> Beer Information</th>
</tr>
<tr>
<td>Time to brew Beer?</td>
<td>25 Minutes</td>
</tr>
<tr>
<td>Brave needed to brew Beer?</td>
<td>5 Brave</td>
</tr>
<td>What does Beer do?</td>
<td>Gives you an energy boost of 25 Energy</td>
</tr>
</table>
<form method='post' action='brewery.php?action=brewbeer'>
<input type='submit' name='brewbeer' value='Brew Beer' />
</form>
  ";

}

function brew_whiskey() {
print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Whiskey</h3>";

echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'> Whiskey Information</th>
</tr>
<tr>
<td>Time to brew Whiskey?</td>
<td>25 Minutes</td>
</tr>
<tr>
<td>Brave needed to brew Whiskey?</td>
<td>10 Brave</td>
</tr>
<td>What does Whiskey do?</td>
<td>25 boost to your brave</td>
</tr>
</table>
<form method='post' action='brewery.php?action=brewbeer'>
<input type='submit' name='brewbeer' value='Brew Whiskey' />
</form>
  ";


}

function brew_beer_sub() {
   if ($_POST['brewbeer']){
global $db,$ir,$c,$userid,$h,$beer;
$beer = rand(1, 6);
       echo "You only had enough ingredients to brew, {$beer} Bottle(s) of Beer!</br>
       Come back in 25 minutes to collect your beer";

$db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid");
$db->query("UPDATE users SET brewed_beer=brewed_beer + $beer WHERE userid=$userid");
$db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid");
$db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); 
if($ir['brew_time'] == 0) {

}
}
}

function drink_beer() {

global $db, $ir, $c, $userid, $h;
   $query  = $db->query("SELECT `inv_qty` FROM inventory WHERE inv_userid = {$userid} AND `inv_itemid` = 277");
$itemid = $db->num_rows($query);
if (!$db->num_rows($query)) {
       echo "You don't have enough beer";
       die;
   } else {
       echo "You drank 1 Bottle of Beer, you gained 20 energy";
       $db->query("UPDATE users SET energy=energy + 1 WHERE userid=$userid");
       item_remove($userid, 277, 1);
   }
}

function collect_beer() {

global $db, $ir, $c, $userid, $h;


print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Collect Beer</h3>";

echo "You have ". number_format($ir["brewed_beer"]) ." Bottles of Beer, how many would you like to collect?";

echo "<form method='post' action='brewery.php?action=beercollected'>
Beer(s): <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='10' />
</br><input type='submit' name='beercollected' value='Collect' />
                               </form>";

}

function beer_collected() {

global $db, $ir, $c, $userid, $h, $_POST;
$ir['brewed_beer']= abs((int) $ir['brewed_beer']);
if($_POST['amount'] > $ir['brewed_beer']){
echo "You don't have this much beer you only have ". number_format($ir["brewed_beer"]) ." Bottles of Beer"; 
$h->endpage();
  die;
}else{
echo "You have collected ". number_format($ir["amount"]) ." Bottles of Beer, you have ". number_format($ir["brewed_beer"]) ." left";
$db->query("UPDATE users SET brewed_beer=brewed_beer - {$ir['brewed_beer']} WHERE userid=$userid");
item_add($userid, 277, ($_POST['amount']));

}
}
?>

 

I'm getting this here, I set the table as 5 and only wanted to collect 1

This is what I get:

You have collected 0 Bottles of Beer, you have 0 left

When I should get:

You have collected 1 Bottles of Beer, you have 4 left

And it's also setting "brewed_beer" back to 0

Edited by -BRAIDZ-
Link to comment
Share on other sites

Errrm. Although they've got better, I'd still avoid them.

 

It was better than nothing :P

[MENTION=68406]-BRAIDZ-[/MENTION]

You need to look at articles, videos or the php documentation. You will not learn what each keyword, function or statement actually does without it. You are literally shooting yourself in the foot by refusing to look at anything. I know you said it was confusing, but its going to be. Also, using mccodes to try learn php is a big no no. Mccodes is php in its worst possible form.

Following what [MENTION=65371]sniko[/MENTION] has posted

From php.net : http://php.net/manual/en/tutorial.php

http://www.homeandlearn.co.uk/php/php.html

http://www.codecademy.com/en/tracks/php

as for your problem. You need to learn to read your code:

echo "You have collected ". number_format($ir["amount"]) ." Bottles of Beer, you have ". number_format($ir["brewed_beer"]) ." left";

$ir['amount'] doesnt exist....

it should be $_POST['amount']

also, do you have a cron running anywhere that sets brewed_beer to 0?

Link to comment
Share on other sites

It was better than nothing :P

[MENTION=68406]-BRAIDZ-[/MENTION]

You need to look at articles, videos or the php documentation. You will not learn what each keyword, function or statement actually does without it. You are literally shooting yourself in the foot by refusing to look at anything. I know you said it was confusing, but its going to be. Also, using mccodes to try learn php is a big no no. Mccodes is php in its worst possible form.

Following what [MENTION=65371]sniko[/MENTION] has posted

From php.net : http://php.net/manual/en/tutorial.php

http://www.homeandlearn.co.uk/php/php.html

http://www.codecademy.com/en/tracks/php

as for your problem. You need to learn to read your code:

echo "You have collected ". number_format($ir["amount"]) ." Bottles of Beer, you have ". number_format($ir["brewed_beer"]) ." left";

$ir['amount'] doesnt exist....

it should be $_POST['amount']

also, do you have a cron running anywhere that sets brewed_beer to 0?

I will have a read through, and okay thanks, I will try that, and no I don't, why is that?

Link to comment
Share on other sites

I'm sorry but I am going to sound like an ass here but I feel it's for your own good.

i don't see what is so confusing about this, coly and sniko have helped you immensely and have pretty much given you almost a fully functional system here. If you understood the way PHP works regardless of Framework/Script you would have this done by now. The reason you are not understanding what is being offered to you is because you refuse to try to learn, expect people to do it for you so you can copy/paste and expect it to work. But guess what? It's not going to happen. You can't troubleshoot because you have no clue to what is actually going on in your script. This is all basic stuff and nothing out of the ordinary.

Please se take the time to read the documentation that has been provided to you and learn it

Link to comment
Share on other sites

I'm sorry but I am going to sound like an ass here but I feel it's for your own good.

i don't see what is so confusing about this, coly and sniko have helped you immensely and have pretty much given you almost a fully functional system here. If you understood the way PHP works regardless of Framework/Script you would have this done by now. The reason you are not understanding what is being offered to you is because you refuse to try to learn, expect people to do it for you so you can copy/paste and expect it to work. But guess what? It's not going to happen. You can't troubleshoot because you have no clue to what is actually going on in your script. This is all basic stuff and nothing out of the ordinary.

Please se take the time to read the documentation that has been provided to you and learn it

/reiterating

Link to comment
Share on other sites

while(!-BRAIDZ-_understands){
?>
I'm sorry but I am going to sound like an ass here but I feel it's for your own good.

i don't see what is so confusing about this, coly and sniko have helped you immensely and have pretty much given you almost a fully functional system here. If you understood the way PHP works regardless of Framework/Script you would have this done by now. The reason you are not understanding what is being offered to you is because you refuse to try to learn, expect people to do it for you so you can copy/paste and expect it to work. But guess what? It's not going to happen. You can't troubleshoot because you have no clue to what is actually going on in your script. This is all basic stuff and nothing out of the ordinary. 

Please se take the time to read the documentation that has been provided to you and learn it
<?php
}
Link to comment
Share on other sites

while(!-BRAIDZ-_understands){
?>
I'm sorry but I am going to sound like an ass here but I feel it's for your own good.

i don't see what is so confusing about this, coly and sniko have helped you immensely and have pretty much given you almost a fully functional system here. If you understood the way PHP works regardless of Framework/Script you would have this done by now. The reason you are not understanding what is being offered to you is because you refuse to try to learn, expect people to do it for you so you can copy/paste and expect it to work. But guess what? It's not going to happen. You can't troubleshoot because you have no clue to what is actually going on in your script. This is all basic stuff and nothing out of the ordinary. 

Please se take the time to read the documentation that has been provided to you and learn it
<?php
}

 

Aaaaaand to be that guy, you can't have "-" in variable names or constants.

Link to comment
Share on other sites

Now when I input the number of Bottles of Beer I want to exchange, it truncates my function brewed_beer
<?php  
require_once("globals.php");

if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); }
if($ir['brew'] == 10) {
  echo 'You have already brewed 10 times today, come back tomorrow';
  $h->endpage();
  die;
}

$_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : '';
switch($_GET['action']){

       case 'beer': brew_beer(); break;
       case 'drinkbeer': drink_beer(); break;
       case 'brewbeer': brew_beer_sub(); break;
       case 'whiskey': brew_whiskey(); break;
       case 'collectbeer': collect_beer(); break;
       case 'beercollected': beer_collected(); break;
       default: brewery(); break;
}

function brewery() {
global $db,$ir,$c,$userid,$h;


  print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'> 
<table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table>

<h3>Your Brewery</h3>";

  echo "
You are sitting in your shed.
</br>What would you like to brew?</br>";

  echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'>Brewery Options</th>
</tr>
<tr>
<td>Beer</td>
<td> <a href='brewery.php?action=beer'>Brew</a> </td>
</tr>
<tr>
<td>Whiskey</td>
<td> <a href='brewery.php?action=whiskey'>Brew</a> </td>
</tr>
</tr>
<tr>
<td>Cider</td>
<td> <a href='brewery.php?action=cider'>Brew</a> </td>
</tr>
</tr>
<tr>
<td>Vodka</td>
<td> <a href='brewery.php?action=vodka'>Brew</a> </td>
</tr>
</table>
  ";

  echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'>Collection of Alcohol</th>
</tr>
<tr>
<td>Beer</td>
<td> <a href='brewery.php?action=collectbeer'>Collect</a> </td>
</tr>
<tr>
<td>Whiskey</td>
<td> <a href='brewery.php?action=whiskey'>Collect</a> </td>
</tr>
</tr>
<tr>
<td>Cider</td>
<td> <a href='brewery.php?action=cider'>Collect</a> </td>
</tr>
</tr>
<tr>
<td>Vodka</td>
<td> <a href='brewery.php?action=vodka'>Collect</a> </td>
</tr>
</table>
  ";

  print "<h3><font color='red'>This module is not complete and is still in the early stage of production.</br>
  Not all functions will work properly.</font></h3>";

}

function brew_beer() {
print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Beer</h3>";


  echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'> Beer Information</th>
</tr>
<tr>
<td>Time to brew Beer?</td>
<td>25 Minutes</td>
</tr>
<tr>
<td>Brave needed to brew Beer?</td>
<td>5 Brave</td>
</tr>
<td>What does Beer do?</td>
<td>Gives you an energy boost of 25 Energy</td>
</tr>
</table>
<form method='post' action='brewery.php?action=brewbeer'>
<input type='submit' name='brewbeer' value='Brew Beer' />
</form>
  ";

}

function brew_whiskey() {
print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Whiskey</h3>";

echo "
       <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'>
<tr>
<th colspan='3'> Whiskey Information</th>
</tr>
<tr>
<td>Time to brew Whiskey?</td>
<td>25 Minutes</td>
</tr>
<tr>
<td>Brave needed to brew Whiskey?</td>
<td>10 Brave</td>
</tr>
<td>What does Whiskey do?</td>
<td>25 boost to your brave</td>
</tr>
</table>
<form method='post' action='brewery.php?action=brewbeer'>
<input type='submit' name='brewbeer' value='Brew Whiskey' />
</form>
  ";


}

function brew_beer_sub() {
   if ($_POST['brewbeer']){
global $db,$ir,$c,$userid,$h,$beer;
$beer = rand(1, 6);
       echo "You only had enough ingredients to brew, {$beer} Bottle(s) of Beer!</br>
       Come back in 25 minutes to collect your beer";

$db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid");
$db->query("UPDATE users SET brewed_beer=brewed_beer + $beer WHERE userid=$userid");
$db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid");
$db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); 
if($ir['brew_time'] == 0) {

}
}
}

function drink_beer() {

global $db, $ir, $c, $userid, $h;
   $query  = $db->query("SELECT `inv_qty` FROM inventory WHERE inv_userid = {$userid} AND `inv_itemid` = 277");
$itemid = $db->num_rows($query);
if (!$db->num_rows($query)) {
       echo "You don't have enough beer";
       die;
   } else {
       echo "You drank 1 Bottle of Beer, you gained 20 energy";
       $db->query("UPDATE users SET energy=energy + 1 WHERE userid=$userid");
       item_remove($userid, 277, 1);
   }
}

function collect_beer() {

global $db, $ir, $c, $userid, $h;


print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'>
<h3>Collect Beer</h3>";

echo "You have ". number_format($ir["brewed_beer"]) ." Bottles of Beer, how many would you like to collect?";

echo "<form method='post' action='brewery.php?action=beercollected'>
Beer(s): <input style='background: #BCC6CC;' type='text' name='amount' value='1' maxlength='10' />
</br><input type='submit' name='beercollected' value='Collect' />
                               </form>";

}

function beer_collected() {

global $db, $ir, $c, $userid, $h, $_POST;
$ir['brewed_beer']= abs((int) $ir['brewed_beer']);
if($_POST['amount'] > $ir['brewed_beer']){
echo "You don't have this much beer you only have ". number_format($ir["brewed_beer"]) ." Bottles of Beer"; 
$h->endpage();
  die;
}else{
echo "You have collected ". number_format($ir["amount"]) ." Bottles of Beer, you have ". number_format($ir["brewed_beer"]) ." left";
$db->query("UPDATE users SET brewed_beer=brewed_beer - {$ir['brewed_beer']} WHERE userid=$userid");
item_add($userid, 277, ($_POST['amount']));

}
}
?>

 

I'm getting this here, I set the table as 5 and only wanted to collect 1

This is what I get:

You have collected 0 Bottles of Beer, you have 0 left

When I should get:

You have collected 1 Bottles of Beer, you have 4 left

And it's also setting "brewed_beer" back to 0

so it is setting your brew_beer to 0 as you are taking away brew_beer by $ir['brew_beer'] (these two values are the same, so it will equal to 0)

$db->query("UPDATE users SET brewed_beer=brewed_beer - {$_POST['ammount']} WHERE userid=$userid");

Your other is is

echo "You have collected ". number_format($ir["amount"]) ." Bottles of Beer, you have ". number_format($ir["brewed_beer"]) ." left";

this is wrong as $ir["amount"] does not exist this should be

 

echo "You have collected ". number_format($_POST['amount']) ." Bottles of Beer, you have ". number_format($ir['brewed_beer']) ." left";

also why are you doing this(i don't think you should be but i could be wrong!)

$ir['brewed_beer']= abs((int) $ir['brewed_beer']);

instead you should be securing your $_POST

you can do this by doing the following

$_POST['amount'] =
(isset($_POST['amount']) && is_numeric($_POST['amount']))
? abs(intval($_POST['amount'])) : '';
Edited by adamhull
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...