exit function....problem

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

exit function....problem

Post by alexander19 »

Hello everyone!

I got a small problem with the exit function from the weaponshop.php script.
As it shows in the following examples:
The normal WeaponShop
Image

Buying a weapon.
Image

The exit problem.
Image

So as you can see...in the last photo,the yellow column on the right side dissapeared and the footer wont appear anymore .

Here is the page code:

Code: Select all

<?php
include_once 'connect.php';
session_start();

?>
<!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>Weaponshop</title>
<link rel="icon" href="http://www.worldofbattle.co.cc/images/link_icon.gif" type="image/x-icon" />
<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<?php if (isset($_SESSION['player'])) 
  {
    $player=$_SESSION['player'];
 $playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
$pavatar = $playerinfo3['avatar'];
$pchar = $playerinfo3['pclass'];
$pr = $playerinfo3['renown'];
$ps = $playerinfo3['silver'];
$pg = $playerinfo3['gold'];
$pl = $playerinfo3['level'];
$prr = $playerinfo3['rank'];
		 }
	else
	{
	print "Sorry, not logged in  please <A href='login.php'>Login</a><br>";
 exit;}

 ?>
<body>
<div id="container" >


	<div id="header">
	
        </div>
 
   <div id="charstats">
  
   <div class="headerrenown">
   <span class="charstats1">Renown:</span>
  <?php print" <span class='charstats2'>$pr</span>";?>
   </div>
   
   <div class="headerrank">
   <span class="charstats1">Rank:</span>
   <?php print"<span class='charstats2'>$prr</span>";?>
   </div>
   
   <div class="headerlevel">
   <span class="charstats1">Level:</span>
   <?php print"<span class='charstats2'>$pl</span>";?>
   </div>
   
   <div class="headersilver">
   <span class="charstats1">Silver:</span>
   <?php print"<span class='charstats2'>$ps</span>";?>
   </div>
   
   <div class="headergold">
   <span class="charstats1">Gold:</span>
   <?php print"<span class='charstats2'>$pg</span>";?>
   </div>
    
    </div>
    
<div id="main">

<table  height="100%" cellspacing="0" cellpading="0" border="0" >

<tr height="100%">
<td id="mainmenu" valign="top">
<a class = "m_item" href="game.php" title="Hero" target="_self">Hero</a>
<a class = "m_item" href="messages.php" title="Messages" target="_self">Messages</a>
<a class = "m_item" href="highscore.php" title="Highscore" target="_self">Highscore</a>
<a class = "m_item" href="map.php" title="Map" target="_self">Map</a>
<a class = "m_item" href="arena.php" title="Arena" target="_self">Arena</a>
<a class = "m_item" href="inn.php" title="Inn" target="_self">Inn</a>
<a class = "m_item_a" href="weaponshop.php" title="Weaponshop" target="_self">Weaponshop</a>
<a class = "m_item" href="armorshop.php" title="Armorshop" target="_self">Armorshop</a>
<a class = "m_item" href="store.php" title="Store" target="_self">Store</a>
<a class = "m_item" href="spelltrainer.php" title="SpellTrainer" target="_self">Spell Trainer</a>
<a class = "m_item" href="goldseller.php" title="GoldSeller" target="_self">Gold Seller</a>
<div id="inteface_gargoyle">       </div>
</td>
<td id="contentBox" valign="top">
<br />
<table width="550" border="0" cellspacing="0" cellpadding="0">
  <tr>
      <td><table width="150" height="220" border="0" cellspacing="0" cellpadding="0" background="/images/items/weapons/weaponshop.gif">
          </table>
      </td>
      <td><table width="400" height="100" border="0" cellspacing="0" cellpadding="0" background="/images/items/weapons/weaponshopback.jpg">
        <tr>
          <td><div style="text-align:center; color:#4b3e12;font-weight:bold" >Welcome to the weaponshop!<br />
          From here you can buy different weapon types.</td></div>
       </tr>
         </table>
         </td>
  </tr>
</table>
<br />
<br />

<?php

$counter = 0;
$class = $playerinfo3['pclass'];
$level = $playerinfo3['level'];
$pllocation = $playerinfo3['location'];

$inninfo="SELECT * from locations where location='$pllocation' AND type='weaponshop'"; 
$inninfo2=mysql_query($inninfo) or die("could not get player stats!");
$inninfo3=mysql_fetch_array($inninfo2);

if (isset($_GET['bought']))
{
   $bypass=1;
	
	$id=$_GET['id'];
	

$playerid = $playerinfo3['id'];
$class = $playerinfo3['pclass'];
$level = $playerinfo3['level'];

$iteminfo="SELECT * from weapons where id='$id'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if ($playerinfo3['silver'] < $iteminfo3['price'])
{
 echo "<div class='font1' >You do not have enough Silver for this purchase!</div>";
 echo "<center><a href='weaponshop.php'><div class='font2'>Go Back</div></center>";
  exit;
}


if ($playerinfo3['pclass'] != $iteminfo3['class'] && $iteminfo3['class'] != "any")
{
 echo "<div class='font1'>You are not the right class for this item!</div>";
 echo "<center><a href='weaponshop.php'><div class='font1'>Go Back</div></center>";
  exit;
}




$name = $iteminfo3['name'];
$rating = $iteminfo3['rating'];
$wlevel = $iteminfo3['level'];
$price = $iteminfo3['price'];
$hittext = $iteminfo3['hittext'];
$damage = $iteminfo3['damage'];
$imgurl = $iteminfo3['imgurl'];
$description = $iteminfo3['description'];
$randid = rand(1000,999999999);

$itembought = "INSERT into playerweapons(pid, name, rating, level, randid,price,class,hittext,damage,imgurl,description) VALUES ('$playerid','$name','$rating','$wlevel','$randid','$price','$class','$hittext','$damage','$imgurl','$description')";
mysql_query($itembought) or die("could not insert weapon into backpack");
$updateplayer="update players set silver=silver-'$iteminfo3[price]' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

echo "<div class='font1'>" .$name.  "Purchased</div>";
 echo "<center><a href='weaponshop.php'><div class='font2'>Go Back</div></center>";
print "<br />";
}
  if ($bypass != 1)
 {
$counter = 0;
	 echo "<img src='images/interface/weaponth.gif'>";
      print "<table border='0' width='545' cellspacing='2' cellpadding='2' style='margin-top: -2px; padding-top: 0px;'>";
      $invinfo="SELECT * from weapons where level = '$level' || class='any'";
      $invinfo2=mysql_query($invinfo) or die("could not select anything from the store.");
      print "<table border='0'width='545' bordercolor='white' background='images/interface/weapontm.gif'>";
      print "<tr><td><div class='font1'>Overview</div></td><td><div class='font1'>Description</div></td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      $counter = 1;
	  
	  $percentage = $inninfo3['price'] / 100;
	  $price = $invinfo3['price'] * $percentage;
	  $newprice = $price + $invinfo3['price'];
	  $newprice = (int)$newprice;
      print "<tr><td><img src='$invinfo3[imgurl]'></td><td><div class='font3'>$invinfo3[name]</div><div class='font1'>$invinfo3[description]</div><div class='font1'>Rating:$invinfo3[rating]<br>Damage:$invinfo3[damage]<br>Class:$invinfo3[class]<br>Price:$newprice<br></div></td><td><A href='weaponshop.php?id=$invinfo3[id]&bought=1'><div class='font2'>Buy Weapon</div></td></tr>";
      
      }
      print "</table>";
echo "<img src='images/interface/weapontf.gif'>";
echo " <td  id='rightblock' valign='top'></td>";
      print "</td></tr></table>";

      echo "</small>";

      if ($counter == 0)
      {
            echo "<center>There is nothing in the store at this time.<br>";
            exit;			
      }
 }
  
  ?>

  </div>
<td  id="rightblock" valign="top"></td>
	</td>
    </tr>
   											
</table>

<table width="999"  cellspacing="0" cellpading="0" border="0">
<div id="footer">
<div class="footer_menu">
	<span class="footer_menu"><a href="profile.php">Profile</a><img src="images/star.gif" /></span>
		<span class="footer_menu"><a href="forum.php" target="_blank">Forum</a><img src="images/star.gif" /></span>
       <span class="footer_menu"><a href="chat.php">Chat</a><img src="images/star.gif" /></span>
		<span class="footer_menu"><a href="logout.php">Logout</a><img src="images/star.gif" /><br />
        Swordsmen Entertainment 2010</span
        ></div>
            </div>
</table>

</div>
</div>
</body>
</html>



I guess that the problem comes from this code(rows 137-150):

Code: Select all

if ($playerinfo3['silver'] < $iteminfo3['price'])
{
 echo "<div class='font1' >You do not have enough Silver for this purchase!</div>";
 echo "<center><a href='weaponshop.php'><div class='font2'>Go Back</div></center>";
  exit;
}


if ($playerinfo3['pclass'] != $iteminfo3['class'] && $iteminfo3['class'] != "any")
{
 echo "<div class='font1'>You are not the right class for this item!</div>";
 echo "<center><a href='weaponshop.php'><div class='font1'>Go Back</div></center>";
  exit;
}
My question is,why does the exit function ends all the code including the html and css ones.
Any help would be greatly appreciated.

Alexander,
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: exit function....problem

Post by PaxBritannia »

The answer: because exit exits the script!

Instead of using exit, create a function which prints out the footer and all the elements which are placed after the content.

e.g.:
function finishedscript (){
*insert footer here*
exit;
}

When you want to exit, now use the function instead.

Pax.
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: exit function....problem

Post by alexander19 »

Thx a lot man that really worked. :D
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: exit function....problem

Post by PaxBritannia »

No problem, always glad to help.

Pax.
Post Reply

Return to “Advanced Help and Support”