I'm editing a script another programmer wrote to upload more than one document, however, the script is assuming that a previous document has already been uploaded. When that's the case (there's already a previous document uploaded) the script executes correctly. However, when there's no previous document (i.e. it's the first upload) the script won't execute, instead the page just refreshes.
I've tried going through the script multiple times to locate the problem myself, however PDOs are not my strong point and its likely I glanced over it.
If someone could act as a second pair of eyes and point me in the right direction it would be greatly appreciated.
Here is the full upload script:
<?php
/*
* attachment.php: Attach a resume to a candidate
*/
require_once 'startups.php';
if(! $session->get('s_isLoggedIn')) {
redirect('/index.php', $_SERVER['REQUEST_URI']);
}
if(isset($_POST["attach_doc"])) {
$id=$_GET['id'];
if (is_uploaded_file($_FILES['resume_doc']['tmp_name'])){
$resume_doc = fopen($_FILES['resume_doc']['tmp_name'], 'rb');
$resume_filetype = $_FILES['resume_doc']['type'];
}else {
$resume_doc = null;
$resume_filetype = null;
}
$qry = "CALL addAttachment(:resume_doc, :resume_filetype, :resume_filename, :id)";
$conn->open();
$stmt = $conn->prepare($qry);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$stmt->bindParam(':resume_doc', $resume_doc, PDO::PARAM_LOB);
$stmt->bindParam(':resume_filetype', $resume_filetype, PDO::PARAM_STR);
$stmt->bindParam(':resume_filename', $_FILES['resume_doc']['name']);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
?>
<html>
<head>
<script>
self.parent.tb_remove();
self.parent.location.reload();
</script>
</head>
</html>
<?
} else {
?>
(following the else statement is some HTML but for sake of simplicity I didn't include it.)
If anything in the code needs clarifying, please let me know.