Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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_Variables_Undefined - Fatal编程技术网

PHP变量未定义

PHP变量未定义,php,variables,undefined,Php,Variables,Undefined,我得到这个php错误 注意:未定义变量:total_earn in/var/www/…/hello.php on 第221行 但是这个变量工作得很好。。 有人能帮我吗&有什么想法吗 <?php $con=mysqli_connect("localhost:3306","***","***","superpayment"); $a="select * from users where ref='".$req_user_info['ref

我得到这个php错误

注意:未定义变量:total_earn in/var/www/…/hello.php on 第221行

但是这个变量工作得很好。。 有人能帮我吗&有什么想法吗

<?php
              $con=mysqli_connect("localhost:3306","***","***","superpayment");
              $a="select * from users where ref='".$req_user_info['refer']."' ";
              $b=mysqli_query($con,$a);
              $c=mysqli_fetch_array($b);
                $mm="select * from configuration where config_name='refer_referer_points' ";
                $nn=mysqli_query($con,$mm);
                $oo=mysqli_fetch_array($nn);


              if($c['id']>0) {
                  $x="select * from users where ref='".$req_user_info['refer']."' ";
                  $q=mysqli_query($con,$x);

              $i=0;
              while($res=mysqli_fetch_array($q))
              {
                  $i++;

                 $x="select count(*) as ld, sum(points_used) as earn from Completed where username='".$res['username']."' ";
                  $y=mysqli_query($con,$x);

                  $z=mysqli_fetch_array($y);

                  $user_earn=$z['earn']/1000;
                  $your_earn=($user_earn*$oo['config_value'])/100;
                  $total_earn=$total_earn+$your_earn;
              ?>
它的jist是$total\u earn在您执行$total\u earn=$total\u earn+$your\u earn;时尚未初始化$total\u earn;。虽然PHP会自动将其初始化为0,但它让您知道,如果不初始化它,则可能是代码中的错误

当您可能意外拼错一个变量时,它会很有帮助。有关这方面的更多信息,请参阅

这样设置:

$i=0;
$total_earn=0;
while($res=mysqli_fetch_array($q))
{
    $i++;
    $x="select count(*) as ld, sum(points_used) as earn from Completed where username='".$res['username']."' ";
    $y=mysqli_query($con,$x);

    $z=mysqli_fetch_array($y);

    $user_earn=$z['earn']/1000;
    $your_earn=($user_earn*$oo['config_value'])/100;
    $total_earn=$total_earn+$your_earn;

非常感谢v的快速回复:它很有效