My php code isn't working. Don't know what is wrong...

Discussion in 'PHP' started by 9homie, Jun 8, 2008.

  1. #1
    Hello. (the questions are at the bottom)

    Here is the code:

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Map Code</title>
    </head>
    
    <body>
    
    <?php 
    
    $pokemon = array("Rattata", 
                     "Pidgey" 
                     ); 
    
    $chance = rand(1, 15); 
    
    $pokemon_chance = array_rand($pokemon); 
    if(empty($_GET['start'])){
        echo "<a href='{$_SERVER['PHP_SELF']}?start=1'><img src='Maps/Pallet_town.png' border='0' /></a>";
    }else{
    if ($chance >=1 && $chance <=6 && $pokemon_chance == "Rattata") 
    { 
     echo "<img src='Maps/Pallet_town.png' border='0' />";
     echo "You just found a Rattata"; 
     echo "<img src=\"/pokemon images/Rattata.png\" />\n"; 
     echo "<br />\n"; 
     echo "<input type=\"submit\" value=\"Capture\" name=\"capture\">\n"; 
     echo "<input type=\"submit\" value=\"Battle\" name=\"battle\">\n"; 
    
    } elseif ($chance >=1 && $chance <=6 && $pokemon_chance == "Pidgey") { 
     echo "<img src='Maps/Pallet_town.png' border='0' />";
     echo "You just found a Pidgey"; 
     echo "<img src=\"/pokemon images/Pidgey.png\" />\n"; 
     echo "<br />\n"; 
     echo "<input type=\"submit\" value=\"Capture\" name=\"capture\">\n"; 
     echo "<input type=\"submit\" value=\"Battle\" name=\"battle\">\n"; 
    
    } else {
    
      echo "Sorry, you did not catch a Pokemon";
    
    } 
    
    ?>
    
    </body>
    </html>
    
    Code (markup):
    But when i go onto it.
    1) The picture doesn't work.
    2) The php doesn't work

    What i want it to do is:

    When you click the image, you go onto the php. So if you click the image it gets the random number between 1 and 15 and the pokemon from the array and decides what to do.

    So how do i do it?

    Thank You
    9homie
     
    9homie, Jun 8, 2008 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Are you getting any errors?

    Peace,
     
    Barti1987, Jun 8, 2008 IP
  3. 9homie

    9homie Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nope, not at the moment...
     
    9homie, Jun 8, 2008 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    try this line in place of
    newecho "<a href='".$_SERVER['PHP_SELF']."?start=1'><img src='Maps/Pallet_town.png' border='0' /></a>";

    old
    echo "<a href='{$_SERVER['PHP_SELF']}?start=1'><img src='Maps/Pallet_town.png' border='0' /></a>";
     
    kmap, Jun 8, 2008 IP