大家好,这是我第一次发帖,我觉得这会很好,因为我完全卡住了。我的理解是 PHP 中的 switch 和 If/else 语句没有变量范围。
我的问题是我有一个包含大约 5 行值的 CSV 文件(示例文件),我需要将其放入 mySQL DB 表中(列标题在我的 switch 语句的“案例”中表示)但无论如何我'正在解析 CSV 文件并检查以确保数据在它应该在的列中并将其存储在变量中。然后,我将所有变量存储在一个数组中,该数组被序列化,然后传递到我的 SQL 查询中。
我继续收到错误 SCREAM: Error suppress denied for ( ! ) 注意:未定义的变量:C:\wamp\www\lcimport\serialize.php 中的公司在第 98 行
但我知道这些变量是存在的,因为我可以回显它们并且它们会被调用。但除非这些错误消失,否则我的查询将不会运行,因此不会填充我的数据库表。
我究竟做错了什么?
<?php
//define some constants
$db = 'lc';
mysql_connect('localhost', 'root', '');
mysql_select_db($db);
mysql_error();
$uid = md5(uniqid(time()));
//we only have this here to be a row counter
$row = 1;
if (($handle = fopen("C:\\wamp\\www\\lcimport\\4records.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
//var_dump($data);
// echo $data[0];
echo '';
if ($row === 1) {
$header = $data;
}
$row++;
for ($c=0; $c < $num; $c++) {
//echo $data[$c] . "<br />\n";
if ($row === 2) continue;
switch ($header[$c] ){
case "Contact":
$contact = explode (" ", $data[$c]);
$firstName = $contact[0];
$lastName = $contact[1];
break;
case "Company":
$company = $data[$c];
case "Address1":
//store
$address1 = $data[$c];
break;
case "Address2":
$address2 = $data[$c];
break;
case "Address3":
$address3 = $data[$c];
break;
case "City":
$city = $data[$c];
break;
case "State":
$state = $data[$c];
break;
case "Zip":
$zip = $data[$c];
break;
case "Phone1":
$phone1 = $data[$c];
break;
case "Phone2":
$phone2 = $data[$c];
break;
case "Phone 3":
$phone3 = $data[$c];
break;
case "Fax":
$fax = $data[$c];
break;
case "Accountno":
$accountNo = $data[$c];
break;
default:
$junk = $data[$c];
break;
}
}
echo $company;
$meta = serialize(Array(
"firstname" => $firstName,
"lastname" => $lastName,
"lawfirmname" => $company,
'address' => $address1,
'city' => $city,
'state' => $state,
'zip' => $zip,
'fulladdress' => '',
'officenumber' => $phone1,
'faxnumber' => $fax,
'mobilenumber' => $phone2,
'email' =>'nothing',
'website' => 'somthing.com',
'privacy' => 0,
'status' =>1
));
mysql_query("INSERT INTO `mg_profiles` (meta) VALUES ($meta)");
mysql_error();
}
fclose($handle);
}
?>