Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP不会运行多个查询_Php - Fatal编程技术网

PHP不会运行多个查询

PHP不会运行多个查询,php,Php,这个PHP脚本是为我网站上的“虚拟公司”编写的。这样,当用户向公司发送信用/像素时,应该将其从用户中删除并存入公司帐户 脚本没有返回任何错误,并最终将用户发送到“/me”,因此我认为问题在于没有运行查询 <?php if (isset($_POST['sendmoneyvirk'])) { $credits = mysql_real_escape_string($_POST['credits']); $creditsnew = preg_replace("/[

这个PHP脚本是为我网站上的“虚拟公司”编写的。这样,当用户向公司发送信用/像素时,应该将其从用户中删除并存入公司帐户

脚本没有返回任何错误,并最终将用户发送到“/me”,因此我认为问题在于没有运行查询

  <?php
    if (isset($_POST['sendmoneyvirk'])) {

    $credits = mysql_real_escape_string($_POST['credits']);
    $creditsnew = preg_replace("/[^0-9]/","", $credits);        

    $pixels = mysql_real_escape_string($_POST['pixels']);
    $pixelnew = preg_replace("/[^0-9]/","", $pixels);       


        $getUserinfo = mysql_query("SELECT activity_points, username, credits, online FROM users WHERE id = ".intval($_SESSION['user']['id']));
        while($userinfo = mysql_fetch_array($getUserinfo)) {    
         $pixelsval = $userinfo['activity_points'];
         $creditsval = $userinfo['credits'];
        }


    if ($creditsnew > $creditsval) {
        header('Location: index.php?url=me&error=c1');
        exit;
    }

    if ($pixelsnew > $pixelsval) {
        header('Location: index.php?url=me&error=p1');
        exit;
    } 

    function strip_tags_content($text, $tags = '', $invert = FALSE) { 

      preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags); 
      $tags = array_unique($tags[1]); 

      if(is_array($tags) AND count($tags) > 0) { 
        if($invert == FALSE) { 
          return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text); 
        } 
        else { 
          return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text); 
        } 
      } 
      elseif($invert == FALSE) { 
        return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text); 
      } 
      return $text; 
    }

    mysql_query("UPDATE users SET credits = credits - '".strip_tags_content($creditsnew)."' WHERE id = '$userid'")or die(mysql_error());
    mysql_query("UPDATE companies SET credits = credits + '".strip_tags_content($creditsnew)."' WHERE id = '$virkidnew'")or die(mysql_error());
    mysql_query("UPDATE users SET activity_points = activity_points - '".strip_tags_content($pixelsnew)."' WHERE id = '$userid'")or die(mysql_error());
    mysql_query("UPDATE companies SET pixels = pixels + '".strip_tags_content($pixelsnew)."' WHERE id = '$virkidnew'")or die(mysql_error());

    header('Location: me');
    exit;
    }
?>

首先-您应该看看如何使用mysql,因为mysql\u查询是“过时的”(old and busted)

其次,您可以通过使用查看mysql_查询发生了什么-这将告诉您每次更新更改了多少行-如果任何/所有查询的答案都是0,那么很可能是因为您对查询有一些问题-我建议抓取查询并直接针对数据库运行(使用或类似)调试它

显然,这只是一个代码片段,但看起来$userid可能为空/未设置-值得一看