I have generated a utility to take a csv file and dump the data from csv to database.
The utility is working fine.
Now i want to add the categatory in the combo box
which will come dynamically
Due to categorised value the data will go in the respective table
for eg-->In combo box two values are there
1)Personal information-after selecting this data to be dumped in Personal_Info table
2)Stock Position-->Data to be dumped in Stock_Position table.
Can anyone help me for the same

Dani AI

Generated

Brief practical plan (draws on points from , and but gives a concrete, safe workflow):

Keep a small categories table that drives the combo box (id, name, target_table or a column-mapping). On upload send the selected category id with the CSV. On the server read the category row, map it to an allowed target table and a fixed column list (never interpolate raw user input into SQL), parse the CSV, and insert rows with prepared statements inside a transaction. Below is a compact PHP/PDO sketch that shows the safe mapping+insert pattern.

$cat = $pdo->prepare("SELECT target_table FROM categories WHERE id = ?");
$cat->execute([ (int)$_POST['category_id'] ]);
$target = $cat->fetchColumn();

$mapping = [
  'Personal_Info'  => ['first_name','last_name','email'],
  'Stock_Position' => ['sku','qty','price'],
];

if (!isset($mapping[$target])) throw new Exception('Invalid category');
$cols = $mapping[$target];
$placeholders = implode(',', array_fill(0, count($cols), '?'));
$sql = "INSERT INTO $target (" . implode(',', $cols) . ") VALUES ($placeholders)";
$ins = $pdo->prepare($sql);

$fh = fopen($csvPath,'r');
$header = fgetcsv($fh); // optional: match CSV headers to $cols
$pdo->beginTransaction();
while (($row = fgetcsv($fh)) !== false) {
  $values = array_map('trim', array_slice($row,0,count($cols)));
  $ins->execute($values);
}
$pdo->commit();

Practical cautions: validate column counts or map headers explicitly, handle BOM/encoding, limit file size or stream-process large files, wrap in try/catch and rollback on error, and log failures. Prefer storing column mappings in the DB (or JSON) so you can add categories without code changes. Avoid dynamic SQL from user input — use a whitelist/mapping as shown.

Recommended Answers

All 4 Replies

You won't get free code samples unless you submit something by yourself. Don't let others do your job dude.

There are lots of issue in your project,
1.First you have get the from your database to combobox
2.Second thing get the selected value from database
3.Then save the value back into database

So, if think anyone is to Give copy paste option then forget that you have mention specific problem with your work.
I hope you understand what you have to do next

Use SELECT Statement to retrieve data from database and display to combobox.
User can now select a specific data in combobox then add an INSERT statement to save to your database.

Hope this can help.

I have generated a utility to take a csv file and dump the data from csv to database.
The utility is working fine.
Now i want to add the categatory in the combo box
which will come dynamically
Due to categorised value the data will go in the respective table
for eg-->In combo box two values are there
1)Personal information-after selecting this data to be dumped in Personal_Info table
2)Stock Position-->Data to be dumped in Stock_Position table.
Can anyone help me for the same

Better if u use the SelectedIndex Changed Event and later get the Selected value to be stored in a External Variable, Now use the Update Command by giving the Condition that, if index 0 is selected that is Personal Information u update the Variable's value in the Personal_Info Table, and if 1 do to the Stock_Position table.

Hope it will help u

Regards Kalyan.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.