我想從名爲domains.txt的txt文件中提取數據並將文件的內容插入到數據庫中。下面是我寫的代碼,但不是working.Please幫我從txt文件中提取數據並插入數據庫
<?php
$conn = mysql_connect("localhost","root","");
if (!$conn) {
die("Could not connect: " . mysql_error());
}
mysql_select_db("modify_domains");
$file = fopen("domains.txt", "r");
// Read line by line until end of file
while (!feof($file)) {
// Make an array using comma as delimiter
$array = explode(",",fgets($file));
$domain_name=$array[0];
$reg_email=$array[1];
$tech_email=$array[2];
$billing_email=$array[3];
$admin_email=$array[4];
$password=$array[5];
$sql = "INSERT INTO tbl_domains (domain_name, reg_email, tech_email,billing_email,admin_email,password) VALUES('".$adomain_name"','".$reg_email."',".$tech_email.",".$billing_email.",".$admin_email.",".$password.")";
mysql_query($sql,$conn) or die("Could not connect: " . mysql_error());
// use mysql insert query here
}
?>
那麼_exactly_不工作? –
不工作意味着?你有任何錯誤? – Saty
在SQL字符串中我可以看到你缺少一個「。」在$ adomain_name之後,再加上我認爲你的意思是$ domain_name不是$ adomain_name。我認爲你的問題實際上只是錯別字。它顯示的錯誤消息應該是你需要的全部 –