Web Analytics Made Easy -
StatCounter hmmm i dont get this.... - CodingForum

Announcement

Collapse
No announcement yet.

hmmm i dont get this....

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

  • hmmm i dont get this....

    Hi. i got this script. i getting values from a db. it has a button to update the values. when its clicked it means "upgrading=true". the second that happens, 2 of the values get set to blank. its like they dont exist....

    please dont go off head at me, i got this code in another thread, but this is a new problem i need sorted.
    PHP Code:
    <?
    (!defined('')) ? die : '';
    (!isset(
    $_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
    if ([email protected](
    $_GET['upgrading']))
    {
      
    $user_id=$_SESSION['user_id'];
      
    $tresultmysql_query("SELECT * FROM `user_training`
                          WHERE user_id = 
    $user_id");
    if (
    $train=mysql_fetch_assoc($tresult)){
    $cost=0;
    is_int($cost);
    if (
    is_int($cost)){echo' cost is an int 11 ';}else{echo'cost isnt an int 11';}
    $cost=(int)$train["production_cost"];
    is_string($cost);
    if (
    is_string($cost)){echo' cost is string ';}else{echo'cost isnt astring';}
    is_int($cost);
    if (
    is_int($cost)){echo' cost is an int';}else{echo'cost isnt an int';}
    echo 
    " produciton cost gold is $cost /";print_r($cost);echo' / ';settype($cost"int");
    }else{
    echo 
    'cant set user gfold';
    }
    $uuser_gold=intval($user_gold);
    is_int($uuser_gold);if(is_int($uuser_gold)){echo'uuuuser gold is an int';}else{echo'uuuser gold isnt an int';}
    echo
    ' ++ ';print_r($uuser_gold);echo" +$uuser_gold+ ";
    if (
    $tresult)
    {
      echo 
    'tresult successful';
    }else{
      echo 
    'tresult failed';
    }
      
    $result mysql_query("SELECT * FROM `users`
                          WHERE user_id = '"
    .$user_id."'");
    if (
    $user=mysql_fetch_assoc($result)){
    $user_gold=0;
    is_int($user_gold);
    if (
    is_int($user_gold)){echo' user gold  is an int 1122 ';}else{echo'user gold isnt an int 1122';}
    $user_gold=(int)$user["user_gold"];
    is_string($user_gold);
    if (
    is_string($user_gold)){echo' user gold is string ';}else{echo'user gold isnt astring';}
    is_int($user_gold);
    if (
    is_int($user_gold)){echo' gold is an int';}else{echo'gold isnt an int';}
    echo 
    " user gold is $user_gold / ";print_r($user_gold);echo' / ';settype($user_gold"int");
    }else{
    echo 
    'cant set user gfold';
    }
    if (
    $result)
    {
      echo 
    'result successful';
    }else{
      echo 
    'result failed';
    }
    echo 
    '<table width="90%" cellpadding="0" cellspacing="0" border="0">
           <tr>
                 <td align="left"><b>Unit Production</b></td>
                 <td align="left"><b>Next Level</b></td>
                 <td align="left"><b>Cost</b></td>
           </tr>'
    ;
    while (
    $tmember mysql_fetch_assoc($tresult))
    {
            echo 
    '<tr>
                         <td align="left">'
    .$tmember['unit_production'].'</td>
                 <td align="left">'
    .$tmember['next_lvl'].'</td>
                     <td align="left">'
    .$tmember['production_cost'].'</td>
                </tr>'
    ;
    }
    echo 
    '</table>';
       echo 
    '
    <form action="index.php?mode=training&amp;upgrading=trueamp;" method="POST">
                       Upgrade:  <input type="submit" value="Upgrade" />
                         <input type="hidden" name="Upgrade" value="true" />
    </form>'
    ;
    } else if (@isset(
    $_GET['upgrading'])) {
    $tresultmysql_query("SELECT * FROM `user_training`
                          WHERE user_id = '"
    .$user_id."'");
    $tmember mysql_fetch_assoc($tresult)or die('an error occured in this query:'.$tresult.'. The error is: '.mysql_error()) ;
    echo
    ' //1 ';print_r($user_gold);echo'1 // ';echo" user gold $user_gold";
    echo
    ' //2 ';print_r($cost);echo'2 // ';echo" cost is $cost";
      if (
    $user['user_gold']>=$train['production_cost'])  
      {  
    echo
    ' /1/ print r -';  print_r($user_gold);  echo " /1/ user gold is $user_gold ";
    echo
    ' /1/print r- ';   print_r($cost);           echo " c ost is $cost";  
    $new_user_gold=(int)$user_gold-(int)$cost;  
    if (
    is_int($new_user_gold)){echo' new user gold  is an int';}else{echo'new user gold isnt an int';}  
    echo 
    "new gold is  $new_user_gold / ";  
    print_r($new_user_gold);echo'/';  
         
    $nproduction_lvl=((int)$tmember['unit_production']+1);  
    if (
    is_int($nproduction_lvl)){echo' $nproduciton_lvl is an int';}else{echo'$nproduciton_lvl isnt an int';}  
    echo 
    " produciton cost gold is $cost /";print_r($cost);echo' / '
    $nnext_lvl=((int)$tmember['next_lvl']+1);    
    $addition=0;  
    $addition=$nproduction_lvl+($nproduction_lvl*82);  
         
    $ncost=((int)$addition+($cost*2));  
    echo 
    "new cost is $ncost / ";  
    if (
    is_int($ncost)){echo' new cost  is an int';}else{echo'new cost isnt an int';}  
    settype($ncost"int");print_r(ncost); echo'/';
         
    $user_result mysql_query("UPDATE `users`
                                             SET user_gold = '"
    .$new_user_gold."'
                                            WHERE user_id = '"
    .$_SESSION['user_id']."'");

         
    $tuser_result=mysql_query("UPDATE `user_training`
                                            SET unit_production = '"
    .$nproduction_lvl."',
                                            next_lvl = '"
    .$nnext_lvl."',
                                             production_cost =
    $ncost
                                            WHERE user_id = '"
    .$_SESSION['user_id']."'");

       }else{
         echo 
    'Not enough gold';
         
    timed_redirect('index.php?mode=training'5);
    }

    if (
    $user_result)
    {
      echo 
    'Upgrade Successful!';
      
    timed_redirect('index.php?mode=training'5);
    }else{
      echo 
    'Error Occurred1';
      
    timed_redirect('index.php?mode=training'5);
    }

    if (
    $tuser_result)
    {
      echo 
    'Upgrade Successfu22l!';
      
    timed_redirect('index.php?mode=training'5);
    }else{
      echo 
    'Error Occurre2d: '.$tuser_result.'. The error is: '.mysql_error();
      
    timed_redirect('index.php?mode=training'5);
    }
    }
    echo
    ' //111 ';print_r($user_gold);echo'1 // ';echo" user gold $user_gold";
    echo
    ' //2222 ';print_r($cost);echo'2 // ';echo" cost is $cost";
    ?>
    before i click upgrade $user_gold and $cost are ok. i display it before and after the }else if{ meaning "upgrading" is set to true, both outside of that. and its cool. after i click it, it just sets it to nothing, not even a 0.....why is it doing this??

    EDIT

    this script is simmilar. its to attack another user. imjust checking the details are getting read in but they not. it displays them as 0, when they not, other scripts show the correct details but i cant get this one to....
    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");
        while(
    $auser=mysql_fetch_assoc($uresult)){
            
    $user_attack=(int)$auser['$user_attack_rating'];
            
    $user_gold=(int)$auser['$user_gold'];        
            
    $user_turns=(int)$auser['$user_turns'];
            }
            
    is_int($user_turns);
            if (
    is_int($user_turns)){echo' user turns is int';}else{echo'user turns is not an int';}

            
    is_int($user_gold);
            if (
    is_int($user_gold)){echo' user gold is int';}else{echo'user gold is not an int';}
    is_int($user_attack);
            if (
    is_int($user_attack)){echo' user attack is int';}else{echo'user attack is not an int';}
    echo 
    " user gold is $user_gold  / ";print_r($user_gold);echo' / ';settype($user_gold"int");
            echo 
    "user attack is $user_attack";
            echo 
    "user turns is $user_turns";

    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=(int)$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=(int)$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 
    "!!!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 :(";
    }
    ?>
    Last edited by rross46; Aug 2, 2005, 07:16 PM.
Working...
X