Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [SOLVED] something makes a variable the same as another...

    Hi,
    I've been having probelms with this:
    Every time i execute the script it makes a variable the same as another one.
    But i can't find what part of the code does it.
    Here's my code:
    PHP Code:
               <?php

       $db 
    mysql_connect("localhost""username""password");
       
    mysql_select_db("database"); 
       
    $attackerses $_SESSION['login'];
       
    $attackersessql "SELECT user FROM leden WHERE id='$attackerses'";
       
    $attackersessqlresult mysql_query($attackersessql) or die(mysql_error());
       
    $attackersessqlresultresult mysql_fetch_object($attackersessqlresult);
       
    $attacker $attackersessqlresultresult->user;
       
    $attackerhit1 $_REQUEST["where"];
       
    $attackerhit2 $_REQUEST["where2"];
       
    $attackerhit3 $_REQUEST["where3"];
       
    $defenderhit1 Rand(15);
       
    $defenderhit2 Rand(15);
       
    $defenderhit3 Rand(15);
       
    $defender $_POST['defender'];
       
    $date date(' YYYY-MM-DD ');
          if (
    $attacker && $defender) { 
             
             
    $powersql "SELECT won FROM attacks WHERE won='YES' AND user_name='$attacker'";
             
    $powerresult mysql_query($powersql) or die(mysql_error()); 
             
    $attackerpower1 mysql_num_rows($powerresult);
             
             
    $powersql2 "SELECT won FROM attacks WHERE won='YES' AND user_name='$defender'";
             
    $powerresult2 mysql_query($powersql2) or die(mysql_error());
             
    $defenderpower1 mysql_num_rows($powerresult2);
             
             
    $poepchinees $attackerpower1 10;
             
    $attackerpower Rand($attackerpower1$poepchinees);
             
             
    $poepchinees2 $defenderpower1 10;
             
    $defenderpower Rand($defenderpower1$poepchinees2);
             
             
    $hityes1 $attackerpower 10;
             
    $hityes2 $attackerpower 10;
             
    $hityes3 $attackerpower 10;
             
              if (
    $attackerhit1 $defenderhit1){
              
    $hit '0';
              }
             else { 
             
    $hit $hityes1;
             }
              if (
    $attackerhit2 $defenderhit2){
              
    $hit2 '0';
              }
             else { 
             
    $hit2 $hityes2;
             }
              if (
    $attackerhit3 $defenderhit3){
              
    $hit3 '0';
              }
             else { 
             
    $hit3 $hityes3;
             }
             
             
    $fullattack $hit $hit2 $hit3;
             
             
    $defense $defenderpower 10;
             
             
    $healthdefender $defenderpower;
             
    $healthattacker $attackerpower;
             
            
    $healthdefenderafterattack =  $defenderpower $fullattack;
            
    $healthattackerafterattack =  $attackerpower $defense;
            
            if (
    $healthdefenderafterattack $healthattackerafterattack){
            
    $image "NO";
            }
            if (
    $healthattackerafterattack $healthdefenderafterattack){
            
    $image "YES";
            }
            
             
             
    $existusersql "SELECT user FROM leden WHERE user='$defender'";
             
    $existuserresult mysql_query($existusersql) or die(mysql_error());
             
    $existsuser mysql_fetch_object($existuserresult);
             
             
    $nope "0";
             
             if (!
    $existsuser->user){
             echo(
    "Who The Hell is $defender? He isn't registered here.");
             }
             else {
             
             
    $attacktimessql "SELECT * FROM attacks WHERE user_name='$attacker' AND defender='$defender' AND date='$date'";
             
    $attacktimesresult mysql_query($attacktimessql) or die(mysql_error());
             
    $timesattacking mysql_num_rows($attacktimesresult);
             
             if (
    $attackedtoday >= 24){
             echo (
    "You have exceeded your attacks for today");
             }        
                             elseif (
    $timesattacking >= 2){
                             echo(
    "You can't attack a user more then three times a day");
                             }
                             else {
              
                             
    /* Maak SQL-query */ 
                             
    $sql "INSERT INTO attacks (won, user_name, defender, date) 
                            VALUES ('$image', '$attacker', '$defender', '$date')"

                             
    mysql_query($sql); 
                              echo (
    "You, $attacker have just attacked $defender!<br>$attacker attacks $attackerhit1 !<br> $defender blocks $defenderhit1 !<br><b> Result attack one: $attacker does $hit damage !<b> <br>$attacker shoots $attackerhit2 ! <br> $defender blocks $defenderhit2 ! <br><b> Result Attack 2: $attacker does $hit2 damage!</b> <br> $attacker shoots $attackerhit3 ! $defender blocks $defenderhit3 !<br> <b> Result attack 3: $attacker does $hit3 damage to $defender </b> <br> <b><u>In total, $attacker does $fullattack damage! </b></u><br><i> $defender hits $attacker for $defense damage ! </i><br>Have you wonned the attack: <u> $image </u>! <a href='javascript:history.back()'>Go back</a>"); 
                             }
                exit; 
          } 
          }
    ?>
    it makes $attackerhit1 the same as $defenderhit1.
    $attackerhit2 the same as $defenderhit2.
    $attackerhit3 the same as $defenderhit3.
    Please help me.
    Cheers MPCODER
    Last edited by MPCODER; 04-29-2004 at 09:53 AM.

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Which variable?
    Omnis mico antequam dominus Spookster!

  • #3
    New Coder
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh sorry, i thought i included it.
    it makes $attackerhit1 the same as $defenderhit1.
    $attackerhit2 the same as $defenderhit2.
    $attackerhit3 the same as $defenderhit3.
    CHeers MPCODER

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A clue : if ($attackerhit1 = $defenderhit1){
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New Coder
    Join Date
    Jan 2004
    Location
    The Netherlands
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, but should that matter if they are in the if tag?
    EDIT: It's solved. I set it up as if ($attackhit1 != $defenderhit1){
    $hit = $hityes1; }
    else { $hit = '0'; }
    And it worked.
    CHeers.
    Last edited by MPCODER; 04-29-2004 at 09:52 AM.

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thought it would be ovious, but using "x=y" means "x becomes y" and this doesn't return anything. It just assigns a (new) value to x.
    if (x=5){ will just assign the value 5 to x. Which is what you also got because you didn't use a "==" instead of the "="
    "x == y" will compaire x with y and if they have the same value, it will return True, if not, it will return False. So this is used inside for insance an if-clause to control the flow of your program --> in most cases, to determine which action needs to be exectuted.
    "x != y" does the same, but the returned values are the oposit : returns True is x is defferent from y
    "x===y" does the same but also checks if the variable types are equal. (very useful if 0 does not need to be considerat as False, for instance to further proces the returnvalue of strpos() where 0 is not the same a False ).
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    if(x=y) is sort of irrelevant in PHP, say in C it's a good exception handler for dealing with different data types and not crashing your program.
    Omnis mico antequam dominus Spookster!

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by raf
    I thought it would be ovious, but using "x=y" means "x becomes y" and this doesn't return anything.
    No, actually something gets returned. The returned value is the value of the left-hand part of the expression after the operation. In your example it means that "x" is returned, but "x" has the same value as "y" due to the assignment.


    Quote Originally Posted by Mhtml
    if(x=y) is sort of irrelevant in PHP, say in C it's a good exception handler for dealing with different data types and not crashing your program.
    Irrelevant? Hardly so. One of the most common idioms to proces the result list of a SQL query went like this (before the "foreach" keyword was introduced, and even nowadays it's been used because foreach creates a copy of the list it iterates on):

    Code:
    while ($row = mysql_fetch_array($result)) {
    // do sth. with the dataset...
    print $row['number_of_penguins_shot'];
    }
    This could only work because at the end of the result set, mysql_fetch_array() would return false, thus ending the while loop. And that's just one example. Maybe you meant something different, as I didn't quite understand the part of the C exception handling. Care to elaborate?
    De gustibus non est disputandum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •