I have the following code. I am trying to import a text file into a sql table using php, as suggested by one of the users on this site.
Unfortunately, my import got half errors due to the words "Max and Min" in the file in the text file.
I tried to figure out what I can do to avoid this. Most of the material that I found was to use reserved words in the column name. But my name is not the column that it is inserted into the columns as data.
Can this be avoided since I don’t know how many other reserved words are in the text file, and I need to run my code every time. I can’t interrupt him every time. This is a huge text file, so I can not manually replace the keywords every time.
mysqli_query("CREATE TABLE IF NOT EXISTS `add_feature_id` (
`id_f` INT(10) unsigned NOT NULL AUTO_INCREMENT,
`id_product` INT(10) unsigned NOT NULL,
`id_feature` INT(10) unsigned NOT NULL,
`value` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL
DEFAULT NULL,PRIMARY KEY ( `id_f` ) )",$conn);
$fd = fopen('trial.txt', 'r');
$fheader = fgets($fd);
while (($data = fgetcsv($fd,0, "~")) !== FALSE) {
$id_product = $data[0];
$id_feature = $data[1];
$unitval = $data[2];
$value = mysql_real_escape_string($unitval);
mysqli_query("INSERT INTO `add_feature_id`(`id_product`,`id_feature`,`value`)
VALUES ($id_product,$id_feature,'$value')",$conn) or die(mysql_error());
}
fclose($fd);
$result = mysqli_query("SELECT * FROM `add_feature_id`",$conn);
//I print my result here but i get error while insert is executed
The error I get is
You have an error in the SQL syntax; check the manual that matches the version of your MySQL server for the correct syntax. Maximum and minimum requirements
Minimu 'low entry requirement on line 2
This is the part of my text file where the Max error occurs . and minimum requirements , as seen in the text file below
IMSKU~AttributeID~Value~Unit~StoredValue~StoredUnit(header row)
1006854 ~ 16257 ~Licensing Program: Max and Min Requirements<ul><li>Low entry level requirement</li><li>Minimum 1 server (Band S) OR 5 desktop (Band A)</li></ul> ~ ~ 0.00 ~