setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Check if file is uploaded if(isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) { $file_tmp = $_FILES['file']['tmp_name']; // Read CSV file $csvData = file_get_contents($file_tmp); $rows = explode("\n", $csvData); // Remove header row array_shift($rows); // Parse CSV data and insert into database foreach ($rows as $row) { $data = str_getcsv($row); // Prepare SQL statement $stmt = $conn->prepare("INSERT INTO cleads (name, email, phone, formname, note, details, origin, verticals, business_type, status, country, state) VALUES (:name, :email, :phone, 'crm-portal', :note, :details, :origin, '5', :business_type, 'New', :country, :state)"); $stmt->bindParam(':name', $data[0]); $stmt->bindParam(':email', $data[1]); $stmt->bindParam(':phone', $data[2]); $stmt->bindParam(':note', $data[9]); $stmt->bindParam(':details', $data[5]); $stmt->bindParam(':origin', $data[6]); $stmt->bindParam(':business_type', $data[8]); $stmt->bindParam(':country', $data[13]); $stmt->bindParam(':state', $data[14]); // Execute the SQL statement $stmt->execute(); } echo "Records added successfully"; } else { // echo "No file uploaded or an error occurred while uploading the file."; } } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } // Close the database connection $conn = null; ?>
TH(the first row) will not be added (Ignored), in every uploads the first row have to be there, as provided in the sample csv
Origin: Facebook-Ads, Google-Ads, Linkedin-Ads, Instagram, Messenger, Whatsapp, GMB, Linkedin, Inbound-Call, Outbound-Call, Others
Verticals: beanstalk, inhouse, teenybeans, iimtt, buzzapp, atheneum, teenybeans_curriculum
Country list & code Download
State list & code Download
Upload CSV
Download CSV File