我是准备好的陈述的新手,我有以下代码。它从用户获取csv文件并将其导入数据库。由于一些无法解释的原因,我收到错误column 'name' can not be empty
,这意味着变量$line[0]
为空,但是当我输出它时,我得到了正确的值。
$conn = new mysqli($host, $username, $password, $database);
$insertProductQ = "INSERT INTO products (name, category_id, brand_id, bar_code, gross_weight, less_weight, net_weight, selling_purity, labor_cost, quantity, min_order, purity, design, origin, description, status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$insertProduct = $conn->prepare($insertProductQ);
@$insertProduct->bind_param('ssisddddiiiiiisi', $line[0], $line[1], $brands[$line[10]], $line[2], $line[3], $line[4], $line[5], $line[6], $line[7], $line[8], $line[9], $purity[$line[11]], $design[$line[12]], $origin[$line[13]], $line[14], $line[15]);
while (($line = fgetcsv($file)) !== FALSE) {
print_r($line[0]);
$exec = $insertProduct->execute();
if($exec === FALSE){
$_SESSION['msg']['type'] = 'warning';
$_SESSION['msg']['content'] = 'An error occurred while saving product from line '.($i+1).'. Please fix errors and try again.';
if(DEBUG){
$log = fopen(LOG_FILE, 'a');
fwrite($log, date('Y-m-d H:i:s')." - Failed to insert product in file products.php Line 172. Error: ".$insertProduct->error."\n");
}
$break = 1;
break;
}
}
我做错了什么?