这是我们在单击提交CSV按钮时调用的PHP/xAjax函数,我可以在函数末尾使用一个弹出模式获得响应,该模式具有正确的数据,但不会插入到我们的数据库中。我想知道为什么我可以在页面上返回数据,但一旦我尝试将其发送到mysql,就没有响应。还有HTML代码和Javascript,但我相信这些都没有问题。
$fileHandle = fopen("test.csv", "r");
// Skips Headers in csv file
fgets($fileHandle);
//Loop through the CSV rows.
while (($row = fgetcsv($fileHandle, 10000, ",")) !== FALSE) {
//Print out my column data.
$orderFormData['testdata1'] = $row[0];
if(strlen($orderFormData['testdata1']) == '' ){
$VerifyStatus = 'Missing data in CSV file, please take a look for empty cells.';
}
$orderFormData['testdata2'] = $row[1];
if(strlen($orderFormData['testdata2']) == '' ){
$VerifyStatus = 'Missing data in CSV file, please take a look for empty cells.';
}
$orderFormData['testdata3'] = $row[2];
if(strlen($orderFormData['testdata3']) == '' ){
$VerifyStatus = 'Missing data in CSV file, please take a look for empty cells.';
}
$orderFormData['testdata4'] = $row[3];
if(strlen($orderFormData['testdata4']) == '' ){
$VerifyStatus = 'Missing data in CSV file, please take a look for empty cells.';
}
// Rob //
$orderFormData['Note'] = preg_replace('/[^da-z -,@$%&()_+=*#?.]/i', '', $orderFormData['Note']);
if(strlen($contactFormData['testdata5']) == '' ){
$VerifyStatus = 'Please enter a company contact so that we can get in touch if there are any issues with your order!';
}
$DebugText .= "<BR>".$VerifyStatus;
if ($VerifyStatus == 'OK') {
$query = "INSERT INTO testtable set ".
"Status = "Open", ".
"Source = "testportal", ".
"data1 = "".$orderFormData['testdata1']."",".
"data2 = "".$orderFormData['testdata2']."",".
"data3 = "".$orderFormData['testdata3']."",".
"RecordDate= "".$q_time.""";
$DebugText.= "<BR>".$query;
$result = mysqli_query($GLOBALS['link'], $query);
if (!$result){
$objResponse->addScript('swal("Oops...", "'.$VerifyStatus.'", "error");');
};
$rows_affected=mysql_affected_rows();
$DebugText.= "<BR>rows affected: ".$rows_affected;
if($rows_affected>0){
$objResponse->addScript('Swal("Order Recieved", "Check orders page for updates!");');
$objResponse->addScript('clearForms();');
}
} else{
$objResponse->addScript('swal("Oops...", "'.$VerifyStatus.'", "error");');
}
return $objResponse->getXML();
}
您从未将$VerifyStatus
设置为'OK'
,应该在While启动后立即执行,然后,如果您没有发现将其设置为其他内容的错误,则数据库查询将运行
while (($row = fgetcsv($fileHandle, 10000, ",")) !== FALSE) {
$VerifyStatus = 'OK';