 <p>This library will probably make things a lot easier for you: <a href="https://code.google.com/p/php-csv-parser/" rel="nofollow">https://code.google.com/p/php-csv-parser/</a>. I have used it in a recent project where I need to parse CSVs and insert into a MySQL database.</p> <p>You can choose which table to insert into by using <code>$csv-&gt;getCell($x, $y)</code> where <code>$x</code> and <code>$y</code> point the cell with <code>"Table1"</code> or <code>"Table2"</code> inside.</p> <p>So you could do:</p> <pre><code>$table_name = $csv-&gt;getCell($x, $y); if( $table_name === "Table1" ) { // code to insert into table 1 } else if( $table_name === "Table2" ) { // code to insert into table 2 } </code></pre>