does anyone know how to return error array in a javascript alert box? The code below that I have doesn't do the trick right. Browser returns "Cannot use [] for reading". When using $error without the bracket, browser only returns the word "Array" in the alert box but the error message is not showing. Any help?
echo '<script type="text/javascript">alert("Error: '.$errors[].'");</script>';
Updated to include the extent of my code:
$errors = [];
$target_dirRFP = ('accounts/' . $order_list . '/rfp/');
$file_nameRFP = $_FILES['FileToUploadRFP']['name'];
$file_sizeRFP = $_FILES['FileToUploadRFP']['size'];
$extentionRFP = pathinfo($file_nameRFP, PATHINFO_EXTENSION);
$tempRFP = ($_FILES["FileToUploadRFP"]["tmp_name"]);
$target_fileRFP = ($target_dirRFP . $file_nameRFP);
$valid_formatsRFP = array("pdf");
$target_dirPSA = ('accounts/' . $order_list . '/psa/');
$file_namePSA = $_FILES['FileToUploadPSA']['name'];
$file_sizePSA = $_FILES['FileToUploadPSA']['size'];
$extentionPSA = pathinfo($file_namePSA, PATHINFO_EXTENSION);
$tempPSA = ($_FILES["FileToUploadPSA"]["tmp_name"]);
$target_filePSA = ($target_dirPSA . $file_namePSA);
$valid_formatsPSA = array("pdf");
if(!empty($file_nameRFP)) {
if(in_array($extentionRFP, $valid_formatsRFP) === false) {
$errors[] = "The RFP you selected to upload is not allowed. Only PDF file is permitted.";
}
if (file_exists($target_fileRFP)) {
$errors[] = "Attached RFP: \"'.$file_nameRFP.'\" already exists.\nPlease select another file to upload.";
}
}
if(!empty($file_namePSA)) {
if(in_array($extentionPSA, $valid_formatsPSA) === false ) {
$errors[]="The PSA you selected to upload is not allowed. Only PDF file is permitted.";
}
if (file_exists($target_filePSA)) {
$errors[] = "Attached PSA: \"'.$file_namePSA.'\" already exists.\nPlease select another file to upload.";
}
}
if(empty($errors)==true) {
move_uploaded_file($tempRFP, $target_fileRFP);
move_uploaded_file($tempPSA, $target_filePSA);
$stmt = $DB_CON_C->prepare("INSERT INTO `".$order_list."`
SET first_name = '$first_name', last_name = '$last_name'");
$stmt->execute();
echo '<script type="text/javascript">alert("Submitted.");</script>';
} else {
echo '<script type="text/javascript">alert("Error: ' . implode("; ", $errors) . '");</script>';
}
$errors$errors = [];