更新PHP查詢問題
也許我只是一個虛擬的,看不到我的錯誤。基本上這是函數處理一切背後的數學。它具有多種查詢和更新,並在兩個不同的表中插入..
當我嘗試處理它,它給了我:
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>
For James:
SELECT bid, account, hrly, rhrly, bal FROM billing WHERE bid=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
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 243
UPDATE billing SET bal = 0 WHERE bid =You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1INSERT INTO billingLog (bid, date, hrsOnsite, hrsRemote, timein, descript, total) VALUES ('', '07292011', '2', '2', '2', '2', '0')
$查詢=「SELECT投標,賬戶, hrly,rhrly,bal FROM billing WHERE bid ='。$ bid。''; - 在這裏檢查你的報價,我想你想用雙引號作爲外部報價:$ query =「SELECT bid,account,hrly,rhrly,bal FROM billing WHERE bid ='」。$ bid。「'」; - 這也可能是錯誤的原因(也許是因爲沒有返回?) – Quasdunk
1)嘗試echo'ing你的查詢來檢查它看起來是否正確,2)嘗試echo'ing mysql_error()來查看MySQL是否在理解你的查詢時遇到問題(即使它看起來是正確的)。 – Flambino
是的,第一個查詢看起來不正確,所以$ result是False(但我們猜測這裏的出價可能是一個數字......),當試圖從錯誤中獲取一行時,會導致錯誤消息 – Dilettant