This php insert code is a part of my php script to import values from csv file. I want insert the fld_id by other value setting up in the csv file. Example of csv content: 123456789,title,description where:
data[0] is 123456789
data[1] is title
data[2] is description
If the insert runing on mysql client, the value is correctly insert, but from php page returns an error: the fld_idcat cannot be null.
This is a part of the php code:
/*other code*/
do {
if ($data[0]) {
mysql_query("
INSERT INTO table_imports
(
fld_username,
fld_idcat,
fld_title,
fld_desc,
fld_userimport
)
VALUES
(
'$Username',
(select id_cat from table_category where id_cat_random = '".addslashes($data[0])."'),
'".addslashes($data[1])."',
'".addslashes($data[2])."'
'userImport'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
header('Refresh: 6; URL=finishPage.php');
die(mysql_error());
/*other code*/
How to correct this php insert to pass the value 123456789 at the variable $data[0] inside the select?
I hope to explain my problem
Thanks