PranayStar
PranayStar

Reputation: 68

How to import csv file into mysql database with automatically increment in id into database table.id field is not in file,only on table

I am importing a CSV file which contains 2 fields. But as it is imported, I want that there should be an increment in transactionid. But this id field is not in file. Code for this is in PHP. Database used is MySql. My Code:

do 
{
    if ($data[0])
     {
        mysql_query("INSERT INTO test VALUES
            (
                '".addslashes($data[0])."',
                '".addslashes($data[1])."'
            )
        ");
     }
}
while ($data = fgetcsv($handle,1000,";"));

Upvotes: 3

Views: 993

Answers (3)

Ankit Sharma
Ankit Sharma

Reputation: 396

ok try this code

do 
{
   if ($data[0])
   {
      mysql_query("INSERT INTO test(table name) VALUES
        ('".addslashes($data[0])."','".addslashes($data[1])."')
                 ");
   }
}
while ($data = fgetcsv($handle,1000,";"));

Upvotes: 0

Ankit Sharma
Ankit Sharma

Reputation: 396

You need to specify the name of that table where you really want to import in query.

Upvotes: 1

Anton
Anton

Reputation: 1061

In your table on the id column, set the auto_increment parameter to true/active.

Upvotes: 1

Related Questions