PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
if(isset($_POST['send'])) {
if($newmoney > -1); {
$error .= "You don't have enough money.";
echo "You don't have enough money.";
} if ($pcboughton = 1); {
$error .="You have already brought a refinery today.";
echo "You have already brought a refinery today.";
}
if($error == null) {
mysql_query("UPDATE players SET commercialprocessing='$newcomplants', pcbought='$pcboughton', money='$newmoney' WHERE id='$id'");
echo "You have constructed a Commercial Refinery. You now have ".number_format($newcomplants)." Commercial Refineries and $".number_format($newmoney)." in cash.<br><center><a href='default.php?id=7'>View Nation</a></center>";
} if($error != null);
echo $error;
}
?>
This code basically should allow you to click on a button, the game then searches to see if you have enough money and if you have brought one of these items and then proceeds to give you it, if you meet the conditions, if not, it should fire an error message. That error message doesn't seem to be working, how would I get that and thing working exactly?
Where are $newmoney and $pcboughton and $newcomplaints and $id coming from? If those aren't set then $newmoney > -1 is false, $error will be null, the query won't affect anything and you'll get the "You have constructed..." message with 0 refineries and $0 in cash.
With that code, as long as $_POST[send] is set, the code must necessarily output something. When you say it won't "echo the $error bit", are you saying it does show the success message and the problem is it that happens every time? Posting the rest of the code would be nice too.