Web Analytics Made Easy -
StatCounter annoying error, not getting data in - CodingForum

Announcement

Collapse
No announcement yet.

annoying error, not getting data in

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • annoying error, not getting data in

    hi. i got this code below, i know what the prob is but dunno how to fix it.
    it has a peice of code below

    PHP Code:
    if ([email protected]($_GET['att'])) 
    PHP Code:
    } else if (@isset($_GET['att'])) 
    PHP Code:
    <form action="index.php?mode=attack&amp;att=trueamp;uid='.$target_userid.'" method="POST">
                    
    Turns: <input type="text" name="att_turns" size="10" /><br />
    <
    input type="submit" value="submit" name="Attack"/>
    </
    form>'; 
    the form code is supposed to set att to true but it isnt setting it, and therefore not carrying out the code below it. what am i doing wrong?

    PHP Code:
     <?
    (!defined('')) ? die : '';
    session_start();
    (!isset(
    $_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
    $set = (isset($_GET['set'])) ? $_GET['set'] : '';
    $target_userid = (isset($_GET['uid'])) ? intval($_GET['uid']) : redirect('index.php?mode=members');
    $user_id=$_SESSION['user_id'];
    if ([email protected](
    $_GET['att']))
    {
    $uresult mysql_query("SELECT * FROM users
                           WHERE user_id=
    $user_id");
    if(
    $auser=mysql_fetch_assoc($uresult)){
    $user_attack=$auser['$user_attack_rating'];
    $user_turns=$auser['$att_turns'];
    $user_gold=$auser['$user_gold'];
    echo
    "user gold is $user_gold";
    echo 
    "user attack is $user_attack";
    echo 
    "user turns is $user_turns";
    }else{
    echo 
    'cant set user stats';
    }
    if (
    $auser)
    {
    echo 
    'user succeeded';
    }else{
    echo 
    'user failed';
    }
    $target mysql_query("SELECT * FROM users
                                                    WHERE user_id = '"
    .$target_userid."'");
    if(
    $tar=mysql_fetch_assoc($target)){
    $target_defence=$tar['$user_defence_rating'];
    echo 
    "target defence is $target_defence";
    $gold=$tar['$user_gold'];
    echo 
    "targets gold is $gold";
    }else{
    echo 
    'set target stats';
    }
    if (
    $tar)
    {
    echo
    'target succeeded';
    }else{
    echo 
    'target failed';
    }
    if (
    $target_userid == $_SESSION['user_id'])
            {
                    echo 
    'You cannot attack yourself';
                    
    timed_redirect('index.php?mode=attack&amp;set=no'2);
                    die;
            }
                    echo 
    'Maximum ammount: <b>15</b>
    <form action="index.php?mode=attack&amp;att=trueamp;uid='
    .$target_userid.'" method="POST">
                    Turns: <input type="text" name="att_turns" size="10" /><br />
    <input type="submit" value="submit" name="Attack"/>
    </form>'
    ;
     
    $attack_turns = (isset($_POSTS['att_turns'])) ? intval($_POST['att_turns']) : '';
    echo 
    "turns entered- $attack_turns";
                    echo 
    "user turns- $user_turns";
                                                              echo 
    "!!!use attack $user_attack";
                                                              echo 
    "!!! target def $target_defence";
    //the below code does not seem to be getting carried out.  the attack turns arent getting deducted
    //the users gold is getting set to 0 too
    //is user['user_turns'] getting referenced properly, aswell as the other vars??
    //could you please check each variable and check its getting referenced properly?
    } else if (@isset($_GET['att']))
    {
    echo 
    "turns entered- $attack_turns";
                    if (
    $user_turns >= $attack_turns)
                            {
                                    if (
    $attack_turns && $attack_turns <= 15)
                                            {
                                                            if (
    $user_attack $target_defence)
                                                            {
                                                                    
    $spoils round(((4.3 * ($gold/100)) * $user_turns));
                                                              echo
    "!!! $user_turns";
                                    echo
    " !! $attack_turns";
                                    echo 
    "!!!!  $user_turns";
    $new_gold=$user_gold-$spoils;
    $new_turns=$user_turns-$attack_turns;
    $new_target_gold=$gold-$spoils;
                                                                    
    $user_result mysql_query("UPDATE users
                                                                            SET user_gold = '"
    .$new_gold."',user_turns='".$new_turns."'
                                            WHERE user_id = '"
    .$_SESSION['user_id']."'")or die('an error occured in this query:'.$user_result.'. The error is: '.mysql_error()) ;
                                                                    
    $target_result mysql_query("UPDATE users
                                                                            SET user_gold = '"
    .$new_target_gold."'
                                                                            WHERE user_id = '"
    .$target_userid."'");
                                                                    
    $victory true;
                                                                    
    $outcome 'Victory';
                                                                    echo 
    "Your troops demolish $target' s army, victory is yours" ;
                                                                    echo 
    '<br>You have gained:<br><b>'.$spoils.' Gold</b><br><b></b>';
                                                             } else {
                                                                    
    $victory false;
                                                                    
    $outcome 'Defeat';
                                                                    echo 
    '!! '.$target.' s army beats back your army in a humiliating defeat!' ;
                                           
    $user_resultd mysql_query("UPDATE users
                                            SET user_turns='"
    .$new_turns."'
                                                    WHERE user_id = '"
    .$_SESSION['user_id']."'")or die('an error occured in this query:'.$user_resultd.'. The error is: '.mysql_error()) ;
                                                            }
                                                    
    $result mysql_query("INSERT INTO `attack_log` VALUES ('".$_SESSION['username']."', '".$target['username']."', '".$user['user_attack_rating']."', '".$target['user_def_rating']."', '".$outcome."', '".$spoils."')");
                                                     if (
    $result)
                                                            {
                                                                    echo 
    'Attack Log Updated!';
    }
                                                                    if(
    $user_result)
                                                                            {
                                                                                    echo
    'user Stats updated';
                                                                                     
    timed_redirect('index.php?mode=main'10);
                                                                             } else {
                                                                          echo
    'user stat update failed';
                                                                                     
    timed_redirect('index.php?mode=main'10);
                                                                             }
                                     if(
    $user_resultd)
                                                                            {
                                                                                    echo
    'user Stats updated';
                                                                                     
    timed_redirect('index.php?mode=main'10);
                                                                             } else {
                                                                          echo
    'user stat update failed';
                                                                                     
    timed_redirect('index.php?mode=main'10);
                                                                             }
                                    if(
    $target_result)
                                    {
                                                             echo
    'target Stats updated';
                                                                                     
    timed_redirect('index.php?mode=main'10);
                                                                             } else {
                                                                          echo
    'target stat update failed';
                                                                                     
    timed_redirect('index.php?mode=main'10);
                                                                             }
                                                             
    }
                      }else{
                            echo 
    'You do not have enough turns';
                                           
    timed_redirect('index.php?mode=attack'3);
            }
    }else{echo
    "not att :(";
    ?>

  • #2
    Hi,

    A quick look at the code shows that you are missing a closing bracket '}' at the end of the script.

    I'll look at the rest of the code now.


    bwuk

    Comment


    • #3
      o aye man, cheers for pointing that out lol.

      ok dude, i hope u spot whats wrong

      Comment


      • #4
        Oops never mind.

        Comment


        • #5
          I'm going to warn you as well about the isset() function which can be deceiving at times.
          Take this:
          Code:
          <form>
            <input type="text" name="thisfield" value="" />
            <input type="submit" name="submit" value="Submit" />
          </form>
          Into this:
          PHP Code:

          if (!isset($_POST['thisfield']))
          {
               die(
          'Please enter a value');
          }
          else
          {
               
          // blah blah
              
          echo 'Thank you for submitting';

          No matter what you do, you will never hit a !isset() in this situation, without the use of php code. Do keep that in mind as well for if you have problems with evaluations. Its the main reason why I usually check values using empty() commands instead of isset(), excluding the main initialization of the variable.
          PHP Code:
          header('HTTP/1.1 420 Enhance Your Calm'); 
          Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

          Comment


          • #6
            i fixed it, it was a realy dumb mistake. i got a new prob though.


            the below code is messy. lots of debugging lol. u will see i am putting db data into variables then testing them to see if they are integers then echo'in em. well i got a prob. the vars aint seeming to store anything. dunno why...
            the data is there in the db.

            PHP Code:
             <?
            (!defined('')) ? die : '';
            session_start();
            (!isset(
            $_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
            $set = (isset($_GET['set'])) ? $_GET['set'] : '';
            $target_userid = (isset($_GET['uid'])) ? intval($_GET['uid']) : redirect('index.php?mode=members');
            $user_id=$_SESSION['user_id'];
            if ([email protected](
            $_GET['att']))
            {
            $uresult mysql_query("SELECT * FROM`users`
                                   WHERE user_id=
            $user_id");
                if(
            $auser=mysql_fetch_assoc($uresult)){
                    
            $user_attack=$auser['$user_attack_rating'];
                    
            is_int($user_attack);
                    if (
            is_int($user_attack)){echo' user attack is int';}else{echo'user attack is not an int';}
                    
            $user_turns=$auser['$att_turns'];
                    
            is_int($user_turns);
                    if (
            is_int($user_turns)){echo' user turns is int';}else{echo'user turns is not an int';}
                    
            $user_gold=$auser['$user_gold'];
                    
            is_int($user_gold);
                    if (
            is_int($user_gold)){echo' user gold is int';}else{echo'user gold is not an int';}
            echo 
            " user gold is $user_gld  / ";print_r($user_gold);echo' / ';settype($user_gold"int");
                    echo 
            "user attack is $user_attack";
                    echo 
            "user turns is $user_turns";
                }else{
                    echo 
            'cant set user stats';
            }
            if (
            $auser)
            {
            echo 
            'user succeeded';
            }else{
            echo 
            'user failed';
            }
            $target mysql_query("SELECT * FROM `users`
                                                            WHERE user_id = '"
            .$target_userid."'");
            if(
            $tar=mysql_fetch_assoc($target)){
            $target_defence=$tar["$user_defence_rating"];
            echo 
            "target defence is $target_defence";
            is_int($target_defence);
            if (
            is_int($target_defence)){echo' target def is int';}else{echo'target def is not an int';}
            $gold=$tar["$user_gold"];
            echo 
            "targets gold is $gold";
            is_int($gold);
            if (
            is_int($gold)){echo' target gold is int';}else{echo'target gols is not an int';}
            }else{
            echo 
            'set target stats';
            }
            if (
            $tar)
            {
            echo
            'target succeeded';
            }else{
            echo 
            'target failed';
            }
            if (
            $target_userid == $_SESSION['user_id'])
                    {
                            echo 
            'You cannot attack yourself';
                            
            timed_redirect('index.php?mode=attack&amp;set=no'2);
                            die;
                    }
                            echo 
            'Maximum ammount: <b>15</b>
            <form action="index.php?mode=attack&amp;att=true&amp;uid='
            .$target_userid.'" method="POST">
                            Turns: <input type="text" name="att_turns" size="10" /><br />
            <input type="submit" value="submit" name="Attack"/>
            </form>'
            ;
             
            $attack_turns = (isset($_POSTS['att_turns'])) ? intval($_POST['att_turns']) : '';
            echo 
            "turns entered- $attack_turns";
                            echo 
            "user turns- $user_turns";
                                                                      echo 
            "!!!use attack $user_attack";
                                                                      echo 
            "!!! target def $target_defence";
            //the below code does not seem to be getting carried out.  the attack turns arent getting deducted
            //the users gold is getting set to 0 too
            //is user['user_turns'] getting referenced properly, aswell as the other vars??
            //could you please check each variable and check its getting referenced properly?
            } else if (@isset($_GET['att']))
            {
            echo 
            "turns entered- $attack_turns";
                            if (
            $user_turns >= $attack_turns)
                                    {
                                            if (
            $attack_turns && $attack_turns <= 15)
                                                    {
                                                                    if (
            $user_attack $target_defence)
                                                                    {
                                                                            
            $spoils round(((4.3 * ($gold/100)) * $user_turns));
                                                                      echo
            "!!! $user_turns";
                                            echo
            " !! $attack_turns";
                                            echo 
            "!!!!  $user_turns";
            $new_gold=$user_gold-$spoils;
            $new_turns=$user_turns-$attack_turns;
            $new_target_gold=$gold-$spoils;
                                                                            
            $user_result mysql_query("UPDATE users
                                                                                    SET user_gold = '"
            .$new_gold."',user_turns='".$new_turns."'
                                                    WHERE user_id = '"
            .$_SESSION['user_id']."'")or die('an error occured in this query:'.$user_result.'. The error is: '.mysql_error()) ;
                                                                            
            $target_result mysql_query("UPDATE users
                                                                                    SET user_gold = '"
            .$new_target_gold."'
                                                                                    WHERE user_id = '"
            .$target_userid."'");
                                                                            
            $victory true;
                                                                            
            $outcome 'Victory';
                                                                            echo 
            "Your troops demolish $target' s army, victory is yours" ;
                                                                            echo 
            '<br>You have gained:<br><b>'.$spoils.' Gold</b><br><b></b>';
                                                                     } else {
                                                                            
            $victory false;
                                                                            
            $outcome 'Defeat';
                                                                            echo 
            '!! '.$target.' s army beats back your army in a humiliating defeat!' ;
                                                   
            $user_resultd mysql_query("UPDATE users
                                                    SET user_turns='"
            .$new_turns."'
                                                            WHERE user_id = '"
            .$_SESSION['user_id']."'")or die('an error occured in this query:'.$user_resultd.'. The error is: '.mysql_error()) ;
                                                                    }
                                                            
            $result mysql_query("INSERT INTO `attack_log` VALUES ('".$_SESSION['username']."', '".$target['username']."', '".$user['user_attack_rating']."', '".$target['user_def_rating']."', '".$outcome."', '".$spoils."')");
                                                             if (
            $result)
                                                                    {
                                                                            echo 
            'Attack Log Updated!';
            }
                                                                            if(
            $user_result)
                                                                                    {
                                                                                            echo
            'user Stats updated';
                                                                                             
            timed_redirect('index.php?mode=main'10);
                                                                                     } else {
                                                                                  echo
            'user stat update failed';
                                                                                             
            timed_redirect('index.php?mode=main'10);
                                                                                     }
                                             if(
            $user_resultd)
                                                                                    {
                                                                                            echo
            'user Stats updated';
                                                                                             
            timed_redirect('index.php?mode=main'10);
                                                                                     } else {
                                                                                  echo
            'user stat update failed';
                                                                                             
            timed_redirect('index.php?mode=main'10);
                                                                                     }
                                            if(
            $target_result)
                                            {
                                                                     echo
            'target Stats updated';
                                                                                             
            timed_redirect('index.php?mode=main'10);
                                                                                     } else {
                                                                                  echo
            'target stat update failed';
                                                                                             
            timed_redirect('index.php?mode=main'10);
                                                                                     }

            }
                              }else{
                                    echo 
            'You do not have enough turns';
                                                   
            timed_redirect('index.php?mode=attack'3);
                    }
            }else{echo
            "not att :(";
            }
            ?>

            Comment


            • #7
              They are empty because you don't access the associative array $auser the right way.
              PHP Code:
              $user_attack=$auser['$user_attack_rating']; // <-- this is wrong
              // either do 
              $user_attack_rating 'someDBColumnName';
              ...
              while(
              $auser = ...)
                
              $user_attack $auser[$user_attack_rating];
                ...
              }
              // or 
              while($auser = ...)
                
              $user_attack $auser['someDBColumnName']
                ...

              Furthermore, in one of your echos you use $user_gld, but you have only defined $user_gold.

              dumpfi
              "Failure is not an option. It comes bundled with the software."
              ....../)/)..(\__/).(\(\................../)_/)......
              .....(-.-).(='.'=).(-.-)................(o.O)...../<)
              ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
              ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
              Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

              Comment


              • #8
                hhmmmmmm.....see i got code just lke that for another script, using another table and it works fine. it gets out the data and displays it fine. only prob with that one is its getting stred at a string and not an int. bu its taking the data out.

                Comment


                • #9
                  Well, I would really like to see your other script. Must be a miracle that something like that would ever function.

                  dumpfi

                  Edit: Maybe your other script uses something like this: $user_attack=$auser["$user_attack_rating"];
                  But this is not the same as: $user_attack=$auser['$user_attack_rating'];
                  See http://www.php.net/manual/en/language.types.string.php for a comparison of single and double quoted strings.
                  "Failure is not an option. It comes bundled with the software."
                  ....../)/)..(\__/).(\(\................../)_/)......
                  .....(-.-).(='.'=).(-.-)................(o.O)...../<)
                  ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
                  ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
                  Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

                  Comment


                  • #10
                    this is sort of unrelated, but do you guys actually color all of those words in the PHP scripts?
                    i'm only 12, gimme some slack

                    Comment


                    • #11
                      No, if you surround your code with [ php] [ /php] (without the spaces), it get's automatically coloured and withespaces are preserved.

                      dumpfi
                      "Failure is not an option. It comes bundled with the software."
                      ....../)/)..(\__/).(\(\................../)_/)......
                      .....(-.-).(='.'=).(-.-)................(o.O)...../<)
                      ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
                      ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
                      Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

                      Comment

                      Working...
                      X