PHP Trade Game Currency

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by rooxx102, Jan 20, 2014.

  1. rooxx102

    rooxx102 New Member

    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    This is my code and I need it so when a user type lets say 50 cash it will give the user + 500 bux and -50 cash if they have 50+ cash.
    PHP:
    <center>
    <h1>Trade Currency</h1>
    You Have <? echo "$myU->Bux" ?> Bux and <? echo "$myU->Cash" ?> Cash<p>1
    <font color='orange'>Cash</font> = 10 <font color='green'>Bux</font> <br>
    10 <font color='green'>Bux</font> = 1
    <font color='orange'>Cash</font></p>
    <form action='' METHOD='POST'><b>Amount Cash: </b>
    <input type='text' name='Cash'><br>
    <input type='submit' name='trade' value='Trade'>
    </form>
    <form action='' METHOD='POST'>
    <b>Amount Bux: </b>
    <input type='text' name='Bux'><br>
    <input type='submit' name='trade' value='Trade'>
    </form>
    <?
    $submit = $_POST['submit'];
    $Cash = $_POST['Cash'];
    $Bux = $_POST['Bux'];
    if($User) {
       if (isset($_POST['Cash'])) {
           $Cash = $_POST['Cash'];
           $Bux = 10 * $Cash;
       }
       else
       {
            if(isset($_POST['Bux'])) {
               $Bux = $_POST['Bux'];
               $Cash = $Bux / 10;
            }
       }
    }

    ?>
     
    Last edited by a moderator: Jan 20, 2014
  2. essellar

    essellar Community Advocate Community Support

    Messages:
    3,295
    Likes Received:
    227
    Trophy Points:
    63
    In future, please surround your code with {php}{/php} tags (replace curly braces with square brackets). That will maintain formatting and add syntax highlighting, making it easier for people to read your code and help you.

    You have three closing braces at the end of that snippet, which means you're probably missing an opening
    PHP:
    if (isset($_POST["<fieldname here>"])){
    Your submit button is actually named "trade", so looking for a POST value called "submit" isn't going to get you anywhere.

    That said, there are other problems with this that you're going to want to look after. You have no guarantee that short tags are going to work on the server, so you should start all PHP segments with <?php, not just <?. <font> tags were deprecated 15 years ago with HTML 4. If you absolutely feel that you must do styling inline, use <span style="color: keyword"> instead. Far better, though, would be to use <span class="bux"> and <span class="cash"> instead and put the actual color values into a stylesheet. That way you can change the colours to suit your taste/design throughout the site by changing one value in the stylesheet instead of editing all of your pages.
     

Share This Page