Jump to content

[SOLVED] Need help to create a checking function!


Recommended Posts

Hello everyone! im creating a function for my game that will make players able to buy Territories but im stuck again :P  what i cant remember how i can make a territory buyable only if you have enough money. at this moment you can buy whatever you want the your money will go down to -100000. how can i make a function that says  "IF $geld - 100000 < 0  get error message"

 

do anyone know how to do that?

 

<?

    

$dbres				= mysql_query("SELECT * FROM `[land]` WHERE `id`='{$_GET['id']}'");
    if($profile = mysql_fetch_object($dbres)) {
      $id				    = $profile->id;
      $owning				= ($profile->owner == "none") ? "This land is not captured yet!<br>
Buy it for $100.000 <form method=\"post\"><input type=submit name=buy value=Buy!></form>" : "Owner: <b><a href=viewprofile.php?viewprofile={$profile->owner}>{$profile->owner}</a></b>.";

if($profile->owner =="{$cookieusername}"){

echo "<a href='est.php?type=1'>Start an crew on this land!</a><BR>";
}
  if(isset($_POST['buy'])) {
    $data->url				= preg_replace('/\</','&#60;',$_POST['website']);
    $data->muziek				= preg_replace('/\</','&#60;',$_POST['muziek']);
    $data->info				= preg_replace('/\</','&#60;',substr($_POST['info'],0,500));
    mysql_query("UPDATE `[land]` SET `owner`='{$cookieusername}' WHERE `id`='{$id}'");
    mysql_query("UPDATE `users` SET `geld`=`geld`-'100000' WHERE `username`='$cookieusername'");
    print "  <tr><td class=\"mainTxt\">This land is yours!</td></tr>\n";
  }


      print <<<ENDHTML
<br>
<br>
<center>
<table border=1 cellspacing=0 cellpadding=2 width=30% bordercolor=black class=sub2>
<tr>
<td align=center background=topic.gif>Owner of this land</td>

</tr><tr><tr><td class="mainTxt" align="center">{$owning}</td></tr>
		</table>
		</center>
		</form>

		<br><br><br><br>

<br /><br />
ENDHTML;


    }


?>

To get started it looks like you need to read up on your PHP if statements.

 

Here is a great place to start

 

http://us.php.net/manual/en/control-structures.if.php

 

this should get you in the right direction

<?php
if ($a > $b) {
    echo "a is bigger than b";
    $b = $a;
}
?>

 

This function lets players buy Territorys in the game, but i need to make something that prevent peoples from buying if they dont have enough money, when they try to buy they should get a message saying, "You dont have enough money"

 

i tryed but it didnt work

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.