Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.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_Mysql_Database - Fatal编程技术网

PHP查询问题

PHP查询问题,php,mysql,database,Php,Mysql,Database,更新 也许我只是个傻瓜,看不出我的错误。基本上,这是一个函数,它处理的是其他一切背后的数学问题。它在两个不同的表中有多个查询、更新和插入 当我尝试处理它时,它会给我: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/53/7311353/html/gs/cca/accounts/include/processAct.php on line

更新

也许我只是个傻瓜,看不出我的错误。基本上,这是一个函数,它处理的是其他一切背后的数学问题。它在两个不同的表中有多个查询、更新和插入

当我尝试处理它时,它会给我:

    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/53/7311353/html/gs/cca/accounts/include/processAct.php on line 241
以下是我的功能:

    function calculateBilling(){    

        $date = date('mdY');
        $bid = mysql_real_escape_string($_POST['bid']);
        $account = mysql_real_escape_string($_POST['account']);
        $timein = mysql_real_escape_string($_POST['timein']);
        $desc = mysql_real_escape_string($_POST['desc']);
        $hrs2calc1 = mysql_real_escape_string($_POST['hrly']);
        $hrs2calc2 = mysql_real_escape_string($_POST['rhrly']);


        $query = 'SELECT bid, account, hrly, rhrly, bal FROM billing WHERE bid='.$bid;
        $result = mysql_query($query);
HERES LINE 241 ---->   while($row = mysql_fetch_row($result)){
                $accounttobebilled = $row[1];
                $hrly = $row[2];
                $rhrly = $row[3];
                $curbal = $row[4];
            }

            $sub1 = $hrly * $hrs2calc1;
            $sub2 = $rhrly * $hrs2calc2;
            $subtotal = $sub1 + $sub2;

            $total = $curbal + $subtotal;

            $query2 = 'UPDATE billing SET bal = '.$total.' WHERE bid ='.$bid;

            $result2 = mysql_query($query2);

        // Update Billing Log for this customer

        mysql_query("INSERT INTO billingLog (bid, date, hrsOnsite, hrsRemote, timein, descript, total) VALUES ('$bid', '$date', '$hrs2calc1', '$hrs2calc2', '$timein', '$desc', '$subtotal')");

   }
我认为问题来自我的选择(下拉列表),它在那里发布到脚本:

    <select class="form-dropdown validate[required]" style="width:150px" id="input_5"        name="account">
     <?php
     while($row =          
         mysql_fetch_row($result)){
$bid =$row[0];
$account = $row[1];
echo '<option value="'.$bid.'">'.$account.'</option>';
        }
                    ?>
                </select>

根据提供的信息,很难找出问题所在。最好的解决方案是在运行查询后立即输出mysql_error()

$result = mysql_query($query);
echo mysql_error();

除非您错误地指定了表名或字段名,否则您的
SELECT
语句中的值应该用正确的引号括起来。

这是您的连接

改变

$query = 'SELECT bid, account, hrly, rhrly, bal FROM billing WHERE bid='.$bid.'';

我还假设
bid
是一个整数。否则,您需要报价:

$query = 'SELECT bid, account, hrly, rhrly, bal FROM billing WHERE bid="'.$bid.'"';
这也是错误的

mysql_query("UPDATE billing SET bal = '$total' WHERE bid ='.$bid.'");
应该是

mysql_query("UPDATE billing SET bal = '{$total}' WHERE bid ='{$bid}'");
-- or full concatenation
mysql_query("UPDATE billing SET bal = '" . $total . "' WHERE bid ='" . $bid . "'");

上一次查询也是如此。

对我来说,检查从php生成SQL查询字符串的结果似乎很有帮助,例如
echo$query
(这应该显示第一次查询中假定的错误)。
如果读取字符串没有发现错误,那么通过mysql将其输入测试数据库可能会有很大帮助,尤其是。混合使用sql、php、单引号和双引号并不总是容易写或读的…

如果改用它,您会得到什么输出:

function calculateBilling(){    

    $date = date('mdY');
    $bid = mysql_real_escape_string($_POST['bid']);
    $account = mysql_real_escape_string($_POST['account']);
    $timein = mysql_real_escape_string($_POST['timein']);
    $desc = mysql_real_escape_string($_POST['desc']);
    $hrs2calc1 = mysql_real_escape_string($_POST['hrly']);
    $hrs2calc2 = mysql_real_escape_string($_POST['rhrly']);

    $query = 'SELECT bid, account, hrly, rhrly, bal FROM billing WHERE bid='.$bid;
    echo $query;
    $result = mysql_query($query);
    echo mysql_error();

    while($row = mysql_fetch_row($result)){
        $accounttobebilled = $row[1];
        $hrly = $row[2];
        $rhrly = $row[3];
        $curbal = $row[4];
    }

    $sub1 = $hrly * $hrs2calc1;
    $sub2 = $rhrly * $hrs2calc2;
    $subtotal = $sub1 + $sub2;
    $total = $curbal + $subtotal;

    $query2 = 'UPDATE billing SET bal = '.$total.' WHERE bid ='.$bid;
    echo $query2;
    $result2 = mysql_query($query2);
    echo mysql_error();

    // Update Billing Log for this customer
    $query3 = "INSERT INTO billingLog (bid, date, hrsOnsite, hrsRemote, timein, descript, total) VALUES ('$bid', '$date', '$hrs2calc1', '$hrs2calc2', '$timein', '$desc', '$subtotal')";
    echo $query3;
    mysql_query($query3);
    echo mysql_error();
}

实际上刚刚得到:您的SQL语法有一个错误;检查与您的MySQL服务器版本对应的手册,以了解在第1行$query='从bid='中选择bid、account、hrly、rhrly、bal'附近使用的正确语法。$bid';-请在此处查看您的报价,我猜您希望使用双引号作为外部报价:$query=“选择bid、account、hrly、rhrly、bal FROM billing WHERE bid=”“$bid。”;-这也可能是错误的原因(可能是因为没有返回任何内容?)1)尝试回显您的查询以检查其外观是否正确,2)尝试回显mysql_error()以查看mysql是否在理解您的查询时遇到问题(即使看起来正确)。是的,第一个查询看起来不正确,因此$result为False(但我们在这里猜测,bid可能是一个数字…)当我们重写代码时,尝试从falseWell获取行时,会出现错误消息;-)问题变得不一致,因为错误现在希望不会再出现在这一行。Quasdunk绝对正确-检查您的引用,或者,您的代码也会有sql注入漏洞(请尝试提交“1;TRUNCATE TABLE billing;”,在“bid”post字段中不带双引号…)当我在while循环后回显$hrly时,即使我更改了行,它也不会给我任何信息。您确定它正在循环吗?
$row[1]
etc是否返回值?你需要循环吗?如果
bid
是唯一的,您可以使用
$row=mysql\u fetch\u assoc($result)没有while循环。尝试使用
$row['hrly']while($row=mysql\u fetch\u row($result)){…}
只更新标量变量,所以如果有更多的行(多于1),只有最后一行会被进一步处理,对吗?我想整个html选择都是造成问题的原因。我附和了这个问题,没有得到我的出价。(账单ID)我在“为詹姆斯”下的问题中添加了出价,但不是从上一页发布的。请参见问题中的“我的html选择代码”。表单未正确过帐。您的答案似乎是未设置$bid,可能是因为$U POST['bid']为空。请检查上面的html选择代码。。我不知道为什么它不是。我有一个下拉Id,希望从db动态创建。它根据用户看到的内容提取帐户名,但值为出价。(账单id)它应该与其他内容一起发布投标。
mysql_query("UPDATE billing SET bal = '{$total}' WHERE bid ='{$bid}'");
-- or full concatenation
mysql_query("UPDATE billing SET bal = '" . $total . "' WHERE bid ='" . $bid . "'");
function calculateBilling(){    

    $date = date('mdY');
    $bid = mysql_real_escape_string($_POST['bid']);
    $account = mysql_real_escape_string($_POST['account']);
    $timein = mysql_real_escape_string($_POST['timein']);
    $desc = mysql_real_escape_string($_POST['desc']);
    $hrs2calc1 = mysql_real_escape_string($_POST['hrly']);
    $hrs2calc2 = mysql_real_escape_string($_POST['rhrly']);

    $query = 'SELECT bid, account, hrly, rhrly, bal FROM billing WHERE bid='.$bid;
    echo $query;
    $result = mysql_query($query);
    echo mysql_error();

    while($row = mysql_fetch_row($result)){
        $accounttobebilled = $row[1];
        $hrly = $row[2];
        $rhrly = $row[3];
        $curbal = $row[4];
    }

    $sub1 = $hrly * $hrs2calc1;
    $sub2 = $rhrly * $hrs2calc2;
    $subtotal = $sub1 + $sub2;
    $total = $curbal + $subtotal;

    $query2 = 'UPDATE billing SET bal = '.$total.' WHERE bid ='.$bid;
    echo $query2;
    $result2 = mysql_query($query2);
    echo mysql_error();

    // Update Billing Log for this customer
    $query3 = "INSERT INTO billingLog (bid, date, hrsOnsite, hrsRemote, timein, descript, total) VALUES ('$bid', '$date', '$hrs2calc1', '$hrs2calc2', '$timein', '$desc', '$subtotal')";
    echo $query3;
    mysql_query($query3);
    echo mysql_error();
}