Import CSV File Data through a button

Hello,

I want to be able to click a button and insert the contents of the csv file in a db table. Is there a way to do this in a bulk insert? Any help would be appreciated. Thanks!

Make a Control application with 2 fields:
File(Document)-> call it file1.
Label ->call it message
Put this on the On Validate Event
Change the code below to match your Table and CSV.

$file1={file};
if($file1=="")
{
sc_error_message(“You need to upload a file!”);
}
///
///
$user=[userid];
$now = date(“Y-m-d g:i a”);
////
[ul_session]=$user."_".$now;
///
$clubid=[clubid];
//lets clear out our temp table
$sql=" DELETE FROM temp_players_list WHERE clubid = ‘$clubid’ ";
sc_exec_sql($sql);
// Clean field message used for feedback
{message} = ‘’;
//set session var
date_default_timezone_set(“America/Vancouver”);
$now = date(“Y-m-d g:i a”);
///
if($clubid >=1)
{
// Starts array of File
$arr_file = array();
// Address Directory’s uploader of Application
$path = $this->Ini->path_doc;
// Absolute path of the file
$file = $path . ‘/’ . {file};
$handle = fopen($file, ‘r’);
//{message} .= $file;
if(is_file($file))
{
// auto detect line endings
ini_set(“auto_detect_line_endings”, true);
///
$arr_file = file($file);
while(!feof($handle))
{
// handle each line of the CSV
$arr_line = fgetcsv($handle);
//var_dump($arr_line);
// skip this line if header row
$skip_line = false;
// check to see if this is a header row
if($arr_line[1] == “First Name”)
{
$skip_line = true;
}
if($arr_line[1] == “Last Name”)
{
$skip_line = true;
}
////
if(empty($arr_line[1]))
{
$skip_line = true;
}

	$ul_session = [ul_session];
	if($skip_line == false) 
	{
		$sql = "INSERT IGNORE INTO temp_players_list(clubid,player_first_name,player_last_name,player_email,player_phone,player_rating1,player_rating2,ul_session) VALUES ('";
		$sql .= $clubid . "', '"; 
	    $sql .= trim(addslashes($arr_line[0])) . "', '";//first
		$sql .= trim(addslashes($arr_line[1])) . "', '";//last
		$sql .= trim(addslashes($arr_line[2])) . "', '";//email
		$sql .= trim(addslashes($arr_line[3])) . "', '";//phone
		$sql .= trim(addslashes($arr_line[4])) . "', '";//rating1
	    $sql .= trim(addslashes($arr_line[5])) . "', '";//rating2
		$sql .= $ul_session . "')";
	    sc_exec_sql($sql);
		}     }	}
else {	// not a file
	{message} .= " That is not CSV file!";}
} 
else  { echo "YOU GOT LOGGED OUT!";  }