So there, my formpost.php this is for submitting the form to the database:
<?php
// Database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (isset($_FILES["fileUpload"]) && $_FILES["fileUpload"]["error"] == 0) {
// Function to safely handle user input
function sanitizeInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize user inputs
$formTitle = sanitizeInput($_POST["formTitle"]);
$formDescription = sanitizeInput($_POST["formDescription"]);
// Check if a file was uploaded
if (isset($_FILES["fileUpload"]) && $_FILES["fileUpload"]["error"] == 0) {
$file_name = $_FILES["fileUpload"]["name"];
$file_tmp = $_FILES["fileUpload"]["tmp_name"];
// Move the uploaded file to a desired location
$upload_dir = "uploads/";
$target_file = $upload_dir . basename($file_name);
if (move_uploaded_file($file_tmp, $target_file)) {
// File uploaded successfully, insert data into the database
$sql = "INSERT INTO your_table_name (Title, Description, FilePath) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sss", $formTitle, $formDescription, $target_file);
if ($stmt->execute()) {
echo "Form data and file uploaded successfully!";
} else {
echo "Error inserting data into the database: " . $stmt->error;
}
} else {
echo "Error uploading file.";
}
} else {
echo "File upload failed.";
}
// Close the database connection
$conn->close();
}
?>
and then its always shown HTTP 500 Error, ChatGPT said it was about file_uplouds permission, and its already set to ‘on’ on the PHP Configuration
So, please give me a solution for this, because it always said error as a result