I have this form where i input data and then send to database but it isn't sending and also there is no error showing even after checking the Network dev tool instead it shows success which i echoed out at the end of the php file
HTML
<form id="hd_FU">
<div class="hd_rws flx">
<label for="code">Code</label>
<input type="text" id="code" name="code" placeholder="...">
</div>
<div class="hd_rws flx mails">
<label for="codeT">Title</label>
<input type="text" id="codeT" name="codeT" placeholder="...">
</div>
<div class="hd_rws flx ai updInput">
<small>Upload File</small>
<input type="file" style="width: 100% !important;
margin-left: 0;
margin-top: 5px;" id="hd_file" accept=".pdf, .PDF, .docx, .doc" name="hd_file">
</div>
<button type="submit" id="hdSub" name="hdSub" class="btnSub">Submit</button>
</form>
JS
$('form#hd_FU').submit(function(e) {
var form_data = new FormData(this);
$.ajax({
type: "POST",
url: "./db_bked/uploadHD.php",
data: form_data,
cache:false,
contentType: false,
processData: false,
beforeSend: function() {
$("#hdSub").html('uploading<span class="pgr">....</span>');
},
success: function(data) {
if(data == 'success') {
alert("ok")
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
})
e.preventDefault();
})
PHP
<?php
session_start();
require "../dbconn.inc/conn.php";
$userId = mysqli_real_escape_string($conn, $_SESSION['userId'] ?? "");
$code = $_POST['code'];
$codeT = $_POST['codeT'];
$dlr = "../PDF/handout/";
$uploadedFile = '';
$userproductImg = $_FILES["hd_file"];
$productFileName = $userproductImg['name'];
$productFileTmpName = $userproductImg['tmp_name'];
$productFileSize = $userproductImg['size'];
$productFileError = $userproductImg['error'];
$productFileExt = explode('.', $productFileName);
$productFileActualExt = strtolower(end($productFileExt));
$productFileAllowed = array('pdf', 'PDF');
if (in_array($productFileActualExt, $productFileAllowed)) {
if ($productFileError === 0) {
if ($productFileSize < 100000000) {
$productFiles = uniqid(''. true).".".$productFileActualExt;
$productFileDestination = $dlr.$productFiles;
$uploadedFile = $productFiles;
move_uploaded_file($productFileTmpName, $productFileDestination);
}
}
}
$sql = $conn->prepare("INSERT INTO hd_bk (code, userId, topic, bk_filename) VALUES (?, ?, ?, ?)");
$sql->bind_param("ssss", $code, $userId, $codeT, $uploadedFile);
$sql->execute();
echo "success";
DATABASE
CREATE TABLE `hd_bk` (
`bkId` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`code` text NOT NULL,
`userId` int(11) NOT NULL,
`topic` longtext NOT NULL,
`bk_filename` text NOT NULL,
`bk_date` datetime NOT NULL DEFAULT current_timestamp()
)
Please does anyone know what i need to do cause am not seeing the data in my database - xampp - phpmyadmin