Файл: waphero.ru/pets/pokup.php
Строк: 42
<?
require_once '../core/system.php';
echo only_reg();
$header = 'Покупка питомца';
require_once '../core/head.php';
?>
<?
{
?>
<?php
if($err) echo "<div class='xar'>" , $err , "</div>";
if(isset($_POST['ok'])){
if(isset($_POST['idpets'])){
$pets = mysql_query("SELECT * FROM pets WHERE id='".$_POST['idpets']."'") or die(mysql_error());
$pets_row = mysql_fetch_array($pets);
if(abs($user['gold']) < $pets_row['price']){
echo "<div class='menu'><center>Извини,но у тебя не хватает серебра!</center></div>";
}else{
$query = mysql_query("SELECT COUNT(id_pets) FROM mypets WHERE id_user='".$user['id']."' AND id_pets='".$_POST['idpets']."'") or die(mysql_error());
if(mysql_result($query, 0) > 0){
echo "<div class='menu'><center>Этого питомца ты уже купил !</center></div>";
}else{
$okcar1 = mysql_query("INSERT INTO mypets(id_pets,id_user,pets,petsname,silapets,healthpets,vinoslpets) VALUES('".$_POST['idpets']."','".$user['id']."','".$pets_row['pets']."','".$pets_row['petsname']."','".$pets_row['silapets']."','".$pets_row['healthpets']."','".$pets_row['vinoslpets']."')") or die(mysql_error());
if($okcar1 == true){
$resmon = abs($user['gold']) - $pets_row['price'];
mysql_query("UPDATE `user` SET gold='".$resmon."',pets='".$pets_row['pets']."',petsname='".$pets_row['petsname']."',silapets='".$pets_row['silapets']."',healthpets='".$pets_row['healthpets']."',vinoslpets='".$pets_row['vinoslpets']."',petschek='1' WHERE id='".$user['id']."'") or die(mysql_error());
$_SESSION['pets'] = "pets";
echo "<meta http-equiv='refresh' content='0; URL=/'>";
exit();
}
}
}
}
}
$pets = mysql_query("SELECT * FROM pets WHERE `level` <= '".$user['level']."'") or die(mysql_error());
$pets_row = mysql_fetch_array($pets);
do{
echo "<div class='menu'><br/>";
printf("<img src='%s' alt='%s' height='100'/><br/>
<b>%s</b><br/>
<img src='/images/icon/gold.png' alt='Цена'/> Цена: %s <br/>
<img src='img/heart.png' alt='Здоровье' height='16'/>Сила: %s <br>
<img src='img/power.png' alt='Сила' height='16'/>Здоровье: %s <br>
<img src='img/vin.png' alt='Выносливость' height='16'/>Выносливость: %s <br>
<form action='' method='post'>
<input type='hidden' name='idpets' value='".$pets_row['id']."' />
<center><input type='submit' class='' name='ok' value='Купить питомца' /></center>
</form>
</div>
",$pets_row['pets'],$pets_row['petsname'],$pets_row['petsname'],$pets_row['price'],$pets_row['silapets'],$pets_row['healthpets'],$pets_row['vinoslpets']);
}while($pets_row = mysql_fetch_array($pets));
}
include '../core/foot.php';
?>