Newie, uploading csv and taking field from other table tan invoices

Im trying to upload a csv file to insert into my table invoices, but i have the problem to include class_id corresponding to enrols table.

i cant.

can please some body give me a hand.

$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

if(mysqli_connect_errno()){
echo 'No se pudo conectar a la base de datos : '.mysqli_connect_error();
}

include_once(“import.php”);
if(isset($_POST[‘import_data’])){

// validate to check uploaded file is a valid csv file

$file_mimes = array(‘text/x-comma-separated-values’, ‘text/comma-separated-values’, ‘application/octet-stream’, ‘application/vnd.ms-excel’, ‘application/x-csv’, ‘text/x-csv’, ‘text/csv’, ‘application/csv’, ‘application/excel’, ‘application/vnd.msexcel’, ‘text/plain’);
if(!empty($_FILES[‘file’][‘name’]) && in_array($_FILES[‘file’][‘type’],$file_mimes)){
if(is_uploaded_file($_FILES[‘file’][‘tmp_name’])){
$csv_file = fopen($_FILES[‘file’][‘tmp_name’], ‘r’);

//fgetcsv($csv_file);
// get data records from csv file

while(($pay_record = fgetcsv($csv_file)) !== FALSE){

// Check if employee already exists with same email
// Check if studen already exists with same boleta number

$sql_query = "SELECT student_id, boleta FROM invoices WHERE student_id = '".$pay_record[1]."' AND boleta = '".$pay_record[16]."' ";
$resultset = mysqli_query($conn, $sql_query) or die("database error:". mysqli_error($conn));
if(mysqli_num_rows($resultset)) {
    echo "ARCHIVO YA FUE SUBIDO UNA VEZ, VERIFIQUE!";
} else {

// Extraer Grado de alumno

$st_class = (mysql_query(“SELECT class_id FROM enrols WHERE student_id = '”.$pay_record[1]."’"));

//$st_class = “SELECT class_id FROM enrols WHERE student_id = '”.$pay_record[1]."’";

// Insert a db invoices

$mysql_insert = “INSERT INTO invoices (title, total_amount, class_id, student_id, payment_method, paid_amount, status, school_id, session, created_at, updated_at, boleta )
VALUES(’”.$pay_record[16]."’,’".$pay_record[17]."’, ‘$st_class’, ‘" .$pay_record[1]."’,‘BIbanking’,’".$pay_record[6]."’,‘paid’, ‘1’, ‘1’, now(), now(),’".$pay_record[16]."’)";

mysqli_query($conn, $mysql_insert) or die("database error:".mysqli_error($conn));
}

}

//if(mysqli_num_rows($resultset)) {
// $sql_update = “UPDATE emp set emp_name=’”.$emp_record[1]."’, emp_salary=’"// // .$emp_record[3]."’, emp_age=’".$emp_record[4]."’ WHERE emp_email = ‘"// //.$emp_record[2]."’";
//mysqli_query($conn, $sql_update) or die(“database error:”. mysqli_error($conn// ));
//} else {
// {
// $mysql_insert = “INSERT INTO invoice (student_id, title, description
//amount, amount_paid, payment_method, creation_timestamp, payment_timestamp, // //payment_details, status, year )VALUES(’”.$pay_record[1]."’, ‘"//.$pay_record[4]."’, ‘".$pay_record[16]."’, ‘".$pay_record[6]."’, ‘"//.$pay_record[17]."’, ‘BIbanking’, ‘".$pay_record[9]."’, ‘".$pay_record[9]//."’, ‘".$pay_record[10]."’, ‘paid’, ‘2019-2020’)";
//mysqli_query($conn, $mysql_insert) or die(“database error:”.mysqli_err// //($conn));
//}
//}
fclose($csv_file);
$import_status = ‘?import_status=success’;
} else {
$import_status = ‘?import_status=error’;
}
} else {
$import_status = ‘?import_status=invalid_file’;
}
header(“Location: index.php”.$import_status);

}
?>