我想从名为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。我认为你的问题实际上只是错别字。它显示的错误消息应该是你需要的全部 –