<?php
session_start(); 
include("sql/conn.php"); 
$llym = $_SERVER["HTTP_REFERER"];
$iipp = $_SERVER["REMOTE_ADDR"];
$noww = time();

if (empty($_SESSION['name'])){
	header("Location: index.php");
	include("../sql/close.php");
    exit;
}


   if($_SESSION['jf']<$_SESSION['qf'])
   {
   header("Location: ".$llym);
   exit;
   }
   else
   {
///////////////////////////////////////////////////////////////
$result = mysql_query("SELECT * FROM key1 where idid ='".$_GET['id']."' and number <> '' order by id limit 0,1");
while($row = mysql_fetch_array($result))
{
$_SESSION['keynumber'] = $row['number'];
mysql_query("UPDATE key1 SET number = '' WHERE idid ='".$_GET['id']."' and number = '".$_SESSION['keynumber']."' ");

$_SESSION['jf'] = $_SESSION['jf'] - $_SESSION['qf'];
mysql_query("UPDATE user SET jf = '".$_SESSION['jf']."' WHERE name = '".$_SESSION['name']."'");

mysql_query("INSERT INTO text (name, time, ip, ing, f) 
VALUES ('".$_SESSION['name']."', '".$noww."', '".$iipp."', '[".$row['name']."][".$_SESSION['keynumber']."][".$row['len']."]', '-".$_SESSION['qf']."')");
}
///////////////////////////////////////////////////////////////
   }







header("Location: ".$llym);
include("sql/close.php"); 
?>
