I want to pull data from a txt file called domains.txt and insert the contents of the file into a database. Below is the code i wrote but is not working.Please help me
我想从一个名为domains.txt的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
}
?>
1 个解决方案
#1
0
All text fields must be separated by single quotes (like '".$reg_email."') and don't forget the point to separate text field and vars.
所有文本字段必须用单引号分隔(例如'“。$ reg_email。”')并且不要忘记分隔文本字段和变量的点。
The query should be like that:
查询应该是这样的:
$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."')";
All text fields must be separated with single quotes. Also you could write it like this:
所有文本字段必须用单引号分隔。你也可以像这样写:
$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')";
#1
0
All text fields must be separated by single quotes (like '".$reg_email."') and don't forget the point to separate text field and vars.
所有文本字段必须用单引号分隔(例如'“。$ reg_email。”')并且不要忘记分隔文本字段和变量的点。
The query should be like that:
查询应该是这样的:
$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."')";
All text fields must be separated with single quotes. Also you could write it like this:
所有文本字段必须用单引号分隔。你也可以像这样写:
$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')";