V
V
Vladimir Shiklgruber2015-03-23 04:40:56
PHP
Vladimir Shiklgruber, 2015-03-23 04:40:56

Why is mysqli query not working?

Hello. Here I can not understand.... There are two scripts (almost identical)
The bottom line is that the same sql refuses to work in different scripts.
First script

<?php
function refresh($time, $url = NULL)
{
    if (empty($url)) {
        $url = "{$_SERVER['REQUEST_URI']}";
    }
    die("<meta http-equiv='refresh' content='" . $time . "; url=" . $url . "'>");
}
require_once('../conf/dbc.php');
require_once('../conf/session_start.php');
require_once('../conf/ban.php');
if ((!isset($_SESSION['id'])) or (!isset($_SESSION['nick']))) {
    header("Location: reg.php?err_login=1");
    exit();
}
$oplata = mt_rand(1, 9999999);
$rnd    = mt_rand(11, 9999999);
$summ   = trim($_GET['syma']);
$time   = time();
$id     = trim($_SESSION['id']);
$kl     = mt_rand(1, 99999999);
$magas  = '2147483647';
$xxtea  = '785678567';
$oplata = $dbc->real_escape_string($oplata);
$rnd    = $dbc->real_escape_string($rnd);
$summ   = $dbc->real_escape_string($summ);
$time   = $dbc->real_escape_string($time);
$id     = $dbc->real_escape_string($id);
$kl     = $dbc->real_escape_string($kl);
$magas  = $dbc->real_escape_string($magas);
$salt   = 'fghjghjfhjfjhnbvmnbmvhjgfgjh785678tyutyu76678xcvbxcvb67hdfghdfgh67e657ytryerty5674567ryerty6574567tryertye75467657trhgfbvnhmhkijiluiotyiueuwyertsdrgfhndhgjdtyuerghddjghjhgjfktryudghgfhrthrtdhgfhdtyerghfghrtyer74576ytreuyytu6756yertytryet756745yhhgfnmdfgsreyyrteu676584678677795785687ytujhgfnvgsgomsjgsfguhjhgsdfujsdfgpousgjpsihsgubsfug89e6w5hisfdgbsidfgh5467woaiybvsdfghewtuhrty90w465uiregthshuaert90wuitre97gfuhfsujghhntigfjhtkh90eruheiuhfdiuhtruhghrthr9ugfgijdfngifdgijfgnsdfghwe9065hutriosgdfojdfigodfhgeiurtwhe9057yer9tud9fsoiudfshgert9y435trhgfdiuhgsdiufghidfghfffff';
$hash   = md5(sha1(md5(md5($salt . $oplata . $rnd . $summ . $time . $id . $kl . $magas . $xxtea . $salt) . $salt . $time . $id . $magas . $rnd) . $salt . $time . $id . $magas . $rnd) . $salt . $kl . $kl);
$hash   = hash('sha512', $hash);
$hash   = hash('whirlpool', $hash);
$hash   = hash('ripemd320', $hash);
$hash   = hash('haval256,5', $hash);
$hash   = hash('ripemd320', $hash);
$hash   = hash('snefru', $hash);
$hash   = hash('crc32', $hash);
function curl_onl($domain)
{
    if (!filter_var($domain, FILTER_VALIDATE_URL)) {
        return false;
    }
    $curlInit = curl_init($domain);
    curl_setopt($curlInit, CURLOPT_CONNECTTIMEOUT, 1);
    curl_setopt($curlInit, CURLOPT_HEADER, true);
    curl_setopt($curlInit, CURLOPT_NOBODY, true);
    curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($curlInit);
    curl_close($curlInit);
    if ($response)
        return true;
    return false;
}
$proverka = 'http://igrodel.tk';
if (curl_onl("$proverka")) {
    $t1    = time();
    $query = "Select * from payynament where id_user = '$id' AND status = 'load' LIMIT 1 ";
    $result = mysqli_query($dbc, $query) or die('ошибка при поиске юзера');
    $paynament = mysqli_fetch_array($result);
    if (!empty($paynament)) {
        $t2 = time();
        $t1 = $paynament['time'];
        $t3 = $t2 - $t1;
        if ($t3 <= 360) {
            header("Location: http://stalker.igrodel.tk/payment.php?err=2");
        } else {
            echo '88';
            $query = "UPDATE `payynament` SET `status` = 'eror' where id_user = '$id' AND status = 'load' LIMIT 1 ";
            $result = mysqli_query($dbc, $query) or die('Ошибка передачи запроса к БД1');
            refresh('0', '');
        }
    } else {
        $ch = curl_init('http://igrodel.tk:81/cabinet/funs/pop.php');
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "oplata=$oplata&rnd=$rnd&summ=$summ&time=$time&id=$id&kl=$kl&magas=$magas&hash=$hash");
        $result = curl_exec($ch);
        echo $result;
        curl_close($ch);
        $query = "insert into payynament (`hash`,`time`,`id_user`,`id_plat`,`syma`,`st1`,`st2`,`st3`,`status`) values ('$hash','$time','$id','$oplata','$summ','ok','no','no','load')  ";
        $result_pist = mysqli_query($dbc, $query) or die('ошибка записи ошибки в бд');
        $query = "insert into payynament_log (`id_plat`,`otv1`) values ('$oplata','$result')  ";
        $result_pist = mysqli_query($dbc, $query) or die('ошибка записи ошибки в лог');
        if (empty($result)) {
            $query = "UPDATE `payynament` SET `status` = 'eror' where id_user = '$id' AND status = 'load' LIMIT 1 ";
            $result = mysqli_query($dbc, $query) or die('Ошибка передачи запроса к БД1');
        } else {
            ///////////////////запрос который отказивается работать в другом скрипте			
            $query = "UPDATE `payynament` SET `status` = 'ok' where id_user = '$id' AND status = 'load' LIMIT 1 ";
            $result = mysqli_query($dbc, $query) or die('Ошибка передачи запроса к БД1');
        }
        header("Location: http://stalker.igrodel.tk/payment.php?err=3");
    }
} else {
    header("Location: http://stalker.igrodel.tk/payment.php?err=1");
}
?>

The second script has 1 request (it actually adds gold to the player)
and the second request that refuses to work...
<?php
require_once('../conf/dbc.php');
function text_log($file, $text)
{
    $data = date("y.m.d H:i:s");
    if (file_exists($file)) {
        $fp     = fopen($file, "a");
        $mytext = "" . $data . " ... " . $text . " \n";
        fwrite($fp, $mytext);
        fclose($fp);
    } else {
        $des = fopen($file, "w");
        fclose($file);
        $fp     = fopen($file, "a");
        $mytext = "" . $data . " ... " . $text . " \n";
        fwrite($fp, $mytext);
        fclose($fp);
    }
}
$oplata = $_POST['oplata'];
$rnd    = $_POST['rnd'];
$summ   = $_POST['summ'];
$id     = $_POST['id'];
$kl     = $_POST['kl'];
$magas  = $_POST['magas'];
$time   = $_POST['time'];
$h1     = $_POST['hash'];
$h2     = $_POST['hash1'];
$oplata = $dbc->real_escape_string($oplata);
$rnd    = $dbc->real_escape_string($rnd);
$summ   = $dbc->real_escape_string($summ);
$time   = $dbc->real_escape_string($time);
$id     = $dbc->real_escape_string($id);
$kl     = $dbc->real_escape_string($kl);
$magas  = $dbc->real_escape_string($magas);
$hash1  = hash('crc32', $h1);
$hash1  = md5($hash1 . sha1($rnd . $kl) . $hash1);
$hash1  = hash('sha512', $hash1);
$hash1  = hash('whirlpool', $hash1);
$hash1  = hash('haval256,5', $hash1);
$hash1  = hash('crc32', $hash1);
$summ   = 25 * $summ;
if ($hash1 == $h2) {
    ///////////////////////запрос работает
    $query = "UPDATE `users` SET `money` = `money`+" . $summ . " WHERE `id` = '" . $id . "' LIMIT 1";
    $result = mysqli_query($dbc, $query) or die('Ошибка передачи запроса к БД3');
    ///////////////////////запрос не работает
    $query = "UPDATE `payynament` SET `status` = 'ok' where `id` = '" . $id . "' AND status = 'load' LIMIT 1 ";
    $result = mysqli_query($dbc, $query) or die('Ошибка передачи запроса к БД1');
} else {
    $file = 'eror.txt';
    $text = 'неверный кеш';
    text_log($file, $text);
}
?>

Thanks in advance for your help. (wrappers xxtea and rsa were removed during debugging

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2015-03-23
@Remdev

It is not surprising that something does not work in such code. But still,
maybe a typo and instead of payynament there should have been another word?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question