Debug

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The1corrupted
    New Member
    • Feb 2007
    • 134

    #1

    Debug

    Blah!! I can't figure out what's wrong with this php code and I can't figure out what! My debugger sees no errors in it, yet the script won't run! I know it's not the includes because they run correctly everywhere else except for buytown.post.ph p..

    buytown.php
    [PHP]
    <?php
    session_start() ;
    //$_SESSION['user'] is the logged-in user's id number used to get data.
    echo "<head>
    <title>Empire z! The Online Empire Building Game | Build a Town</title>";
    include ("includes/pageheader.php" ); //included in all pages viewable
    include ("includes/navbar.php"); //included in all pages viewable
    include ("server/db_conn.php"); //Connect to the database

    if (!isset($_SESSI ON['user'])) {

    echo "<script language=\"java script\" type=\"text/javascript\">al ert(\"You must log in to do that!\")
    parent.location =\"login.php\ "</script>";

    } else {
    $id=$_SESSION['user']; //The $_SESSION['user'] would be an id number if it is set.

    $query=mysql_qu ery("SELECT * FROM `users` WHERE `id`='$id'");
    $genarray=mysql _fetch_array($q uery); //General info array

    settype($townco st, "float"); //Float the town cost
    settype($genarr ay['money'], "float");

    $towncost=($gen array['towns']*2800)/3; //Calculate the cost per town
    $cost=round($to wncost, 2); //Round the town costs

    include ("server/buytown.post.ph p");

    echo "
    <td colspan=\"2\">
    .: Buy a Town :.
    </td>
    </tr>
    <tr>
    <td>
    Current Funds:
    </td>
    <td>
    <font color=\"#009900 \"<b>$".round($ genarray['money'], 2)."</b></font>
    </td>
    </tr>
    <tr>
    <td>
    Current Towns:
    </td>
    <td>
    ".$genarray['towns']."
    </td>
    </tr>
    <tr>
    <td>
    Cost Per Town:
    </td>
    <td>
    ".$cost."
    <input type=\"hidden\" value=".$cost." name=\"cost\">
    </td>
    </tr>
    <tr>
    <td>
    Purchase Amount:
    </td>
    <td>
    <input type=\"text\" name=\"numer\" length=\"20\">
    </td>
    </tr>
    <tr>
    <td colspan=\"2\">
    <input type=\"submit\" value=\"Purchas e\">
    <input type=\"submit\" value=\"Confirm Purchase\">
    </td>
    </tr>
    </table>";
    }

    include ("includes/pagefooter.php" ); //At the end of all pages viewable
    mysql_close();
    ?>[/PHP]

    buytown.post.ph p
    [PHP]<?php
    $number=$_POST['number'];

    if ($number!=NULL) {
    if ($genarray['money']>=($cost*$numbe r)) {
    settype($purcha se, "float");
    $purchase=$cost *$number;
    round($purchase , 2);

    mysql_query("UP DATE `users` WHERE `id`='$id' SET `towns`=`towns` +'$number'");

    echo "
    <script language=\"java script\" type=\"text/javascript\">al ert(\"Town built successfully.\" )
    parent.location =\"viewempire.p hp\"</script>";
    } else {
    echo "
    <script language=\"java script\" type=\"text/javascript\">al ert(\"Not enough funds!!\")</script>";
    }
    }
    ?>[/PHP]
  • The1corrupted
    New Member
    • Feb 2007
    • 134

    #2
    Nevermind, I solved the problem.. It was my MySQL syntax. I reversed the SET and WHERE in my buytown.post.ph p.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, The1corrupted.

      Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

      Comment

      • The1corrupted
        New Member
        • Feb 2007
        • 134

        #4
        Yes, actually it seems that I get a majority of my pages right on the first try, just a few tiny syntax errors here and there to occasionally occupy my time, but this is the fastest I've actually ever gotten a site's pages up and running...

        What I have so far can be found at http://empirez.php0h.com

        Though, I warn you about signing up because your account could be deleted due to the MySQL table changes, which are quite frequent as I sometimes find that I was missing a field or two, or just to add new features.

        Comment

        Working...