How to INSERT other value with 'LOAD DATA LOCAL INFILE' ?

Hi there,
I have a multi numbers uploading [to sql table] form :

<input name="uploaded" type="file" required="" accept="text/plain" />

and php code is [php]
$target = “upload/”;
if(isset($_POST[‘submit’])) {
$target = $target . basename( $_FILES[‘uploaded’][‘name’]) ;
$ok=1;
if(move_uploaded_file($_FILES[‘uploaded’][‘tmp_name’], $target))
{
$filename = basename( $_FILES[‘uploaded’][‘name’]) ;

mysql_query("LOAD DATA LOCAL INFILE ‘upload/$filename’
INTO TABLE crm_temp_no
LINES TERMINATED BY ‘\n’
(temp_no) ");

            echo 'successfully uploaded!' ;

}
else {
echo ‘fail’ ;
}
}
[/php]
it is uploading multiple numbers to row name ‘temp_no’ in the table ‘crm_temp_no’. Its okay.
Now, i need to insert a value at extra column ‘data_name’ from : <input type="text" name="dataname" />
This data_name want to insert ALL ROWS at a time.


crm_temp_no.png

What value do you want to show up in the data name? Is it the same value for all rows all the time?

Hi, thanks for replay.

I have 2 form fields.

now, 1st one is done [some mobile numbers from a file]. it is working. All numbers are inserting in ‘temp_no’ sql column.
2nd field name is ‘dataname’, [text field for typing] it want to INSERT in ‘data_name’ column in sql table.

Problem is i don’t know, how to handle ‘dataname’ field value for INSERT to sql.
Please guide me.

I don’t think you want an insert statement, you want an update statement.

[php]mysql_query(“update crm_temp_no set data_name = ’ . $_POST [‘dataname’] . ’ where data_name is null”);[/php]

After you load your table go back and update the data_name column, with the value the user typed in.

*This query will update all rows with blank values in the table. (I’m not sure if that is a concern of yours)

I’m not sure what you’re trying to do in the grand scope, but I would never do something like that. I would structure everything a little differently. But this might work for you.

Dear Topcoder,
Your script full filled my requirement. Very helpfull, Thank you very much.

Sponsor our Newsletter | Privacy Policy | Terms of Service