Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # Script to parse CSV and run each
- # line as its own query
- //assuming you have connected to the database
- //and the form as been submitted
- $lines = explode("\n", $_POST['csv']);
- $i = 0;
- $tally = 0;
- while($line = $lines[$i]){
- $split = str_getcsv($list, ',', '"');
- //arbitrary variable names for examples
- list($id, $name, $salary, $bonus) = $split;
- $q = mysql_query("INSERT INTO users (id, name, salary, bonus)
- VALUES (".$id.", \"".$name."\", ".$salary.", ".$bonus."")
- or die(mysql_error());
- //for what ever reason it doesn't work,
- //it should give you an error anyways.
- if(!$q){
- echo "Error inserting into the database.";
- }else{
- $tally++;
- }
- $i++;
- }
- echo "Total of ".$tally." entries were successful.";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement