Файл: pets/pokup.php
Строк: 56
<?
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><span class='red'>Этого питомца ты уже купил !</span></center></div>";
}else{
$okcar1 = mysql_query("INSERT INTO mypets(id_pets,id_user,pets,petsname,silapets,healthpets,vinoslpets) VALUES('".mysql_real_escape_string($_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 "<center><span class='yellow'> <img src='/images/icon/pit.png'> Питомец успешно куплен</span></center>";
echo" <div class='player menuList'><li><a href='/pets/index.php'><img src='/images/icon/user.png'>Мой питомец</a></li></div><div class='line'></div>";
include '../core/foot.php';
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='75'/><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='bt' name='ok' value='Купить питомца' /></center>
</form>
<div class='dot-line'></div>
</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';
?>