Hi there,
I'm building an online game website and i'm having a bit of trouble getting something to work. You see when the user buys credits, it inputs that into their row in the database. They can then go to the place where they can buy things such as metal and crystal further their strength against other players etc.
When they buy something for say 50 credits, it doesn't add the product e.g metal and it doesn't minus the amount of credits it costs. Here is the code:
<form method="post" action="creditshop.php" name="f">
<tr>
<td width=20 class=mainTxt><input type="radio" name="gebruik" value="crystal"></td>
<td class=mainTxt width="208">+20.000 Crystal</td><td class=mainTxt width="199">60 Credits</td>
</tr>
<?php
$dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"];
$select = mysql_query("SELECT * FROM `game_planets`");
$page = mysql_fetch_object($select);
$login=$user['username'];
<?PHP
$gebruik = htmlspecialchars(addslashes($_POST['gebruik']));
$gebruik = mysql_real_escape_string($gebruik) or die
('Error real escape string');
if (isset($_POST['gebruik'])) {
$aantal = htmlspecialchars(addslashes($_POST['bieden']));
$aantal = substr($aantal,0,2);
if(!is_numeric($aantal)){
echo 'Ongeldige invoer';
exit;
}
if($gebruik == "crystal") {
$gebruik; //=htmlspecialchars(addslashes($_POST['gebruik']));
$kost = 60; //per aantal
$kosttotaal = $kost*$aantal; // totale kost
$wat = 20000; // hoeveel krijg je per keer
$krijgen = $wat*$aantal; // totaal aantal dat men krijgt
}
if($gebruik == "crystal") {
mysql_query("UPDATE `game_planets` SET `belcredits`=`belcredits`-'$kosttotaal' WHERE `name`='$login'");
mysql_query("UPDATE `game_planets` SET `crystal`=`crystal`+'$krijgen' WHERE `name`='$login'");
print " <tr><td class=\"mainTxt\" align=\"center\">You have bought <b>".$wat." crystal</b> <b>$aantal</b> times <br></td></tr>\n";
}
include("config.php");
//mysql_query("INSERT INTO `[bestellingen]` ( `login` , `datum`, `ip` , `gameid`, `belcredits`, `wat`, `aantal`) VALUES ('$data->login', NOW(), '{$_SERVER['REMOTE_ADDR']}', '{$gameid}', '{$kosttotaal}', '{$gebruik}', '{$aantal}')") or die(mysql_error());
}
exit;
?>
It's giving me an error with the real_escape_string and also an "Undefined index: gebruik"
I can't spot what's wrong, can somebody help me out? Thanks!