if (!empty($active_registra)) { echo '<h4 class="alert alert-error">Error</h4>'; echo '<hr>'; echo "You cannot insert into registras table unless you deactivate one or more active registra(s)."; echo '<hr>'; } else { $arrayfiledetails = explode('.', $_FILES['signature']['name']); $extension = $arrayfiledetails[sizeof($arrayfiledetails) - 1]; $_FILES['signature']['name'] = strtolower(str_replace(" ", "_", $_POST['full_name'])) . '_signature.' . $extension; if ($registra->attach_file($_FILES['signature'])) { $registra->full_name = $_POST['full_name']; $registra->year = $_POST['year']; $registra->visible = $_POST['visible']; $registra->created_at = $registra_details->created_at; $registra->updated_at = $current_time; if ($registra->save()) { echo '<h4 class="alert alert-success">Success</h4>'; echo '<hr>'; echo "<p>You have successfully added a new record into registras table</p>"; echo '<hr>'; } else { echo '<h4 class="alert alert-error">Error</h4>'; echo '<hr>'; echo "Failed to insert into registras table."; echo '<hr>'; } } else { echo "file not attached"; print_r($_FILES); } }