我想知道爲什麼我得到了一個錯誤說注意:未定義的變量:query_add_landdev_temp_payroll在C:\ XAMPP \ htdocs中\上線XX運\ AJAX \ ajaxLanddevNTPPayroll.php。在過去的兩週裏,它的工作非常完美。當我今天試圖執行代碼時,我遇到了那種錯誤。這裏是我的代碼:當它的外循環時未定義的變量 - PHP
$query_get_payroll = mysqli_query($new_conn, "SELECT ntp_with_ob_payroll_transaction.ntp_id, ntp_with_ob_payroll_transaction.allotment_code, ntp_with_ob_payroll_transaction.category_name, ntp_with_ob_payroll_transaction.block_number, ntp_with_ob_payroll_transaction.activity, ntp_with_ob_payroll_transaction.lot_number, ntp_with_ob_payroll_transaction.labor_cost, other_budget.quantity FROM ntp_with_ob_payroll_transaction JOIN other_budget ON ntp_with_ob_payroll_transaction.ob_id = other_budget.ob_id WHERE other_budget.transaction_id = $transaction_id AND other_budget.ob_number = '$ntp_number' AND is_payroll = 0");
while($row = mysqli_fetch_assoc($query_get_payroll)) {
$ntp_id = $row['ntp_id'];
$allotment_code = $row['allotment_code'];
$category_name = $row['category_name'];
$block_number = $row['block_number'];
$activity = $row['activity'];
$lot_number = $row['lot_number'];
$labor_cost = $row['labor_cost']; //this is equivalent to unit cost
$quantity = $row['quantity']; //this is equivalent to total percentage
$query_add_landdev_temp_payroll = mysqli_query($new_conn, "INSERT INTO temp_payroll_landdev(ntp_id, userid, transaction_id, ntp_number, contractor_name, allotment_code, category_name, block_number, activity, lot_numbers, regular_labor, quantity) VALUES($ntp_id, $_SESSION[userid], $transaction_id, '$ntp_number', '$fullname', '$allotment_code', '$category_name', $block_number, '$activity', '$lot_number', '$labor_cost', '$quantity')");
}
if($query_add_landdev_temp_payroll) {
echo 1;
//database file name
$database_file = $database.'.sql';
$new_database_file = $new_database.'.sql';
if(file_exists('backup/'.$new_database_file)) {
unlink('backup/'.$new_database_file);
//backup project database
$command = "C:/xampp/mysql/bin/mysqldump --host=$new_host --user=$new_user --password=$new_pass $new_database > backup/$new_database_file";
system($command);
} else {
//backup project database
$command = "C:/xampp/mysql/bin/mysqldump --host=$new_host --user=$new_user --password=$new_pass $new_database > backup/$new_database_file";
system($command);
}
} else {
echo 0;
}
也許這個代碼'$行= mysqli_fetch_assoc($ query_get_payroll)'返回的* falsy *值?因此,while循環沒有運行。 – Wreigh
@Wreigh我沒有注意到...非常感謝。 –
不用客氣,您可以按照Naga的回答來檢查* variable *是否已設置,或者iCoders是否回答以確保*變量*存在。 – Wreigh