How can PHP be used to simultaneously upload a JPG file to a server, insert data into a database, and store the file path in the database?

To achieve this, you can use PHP to handle the file upload, insert data into a database, and store the file path in the database. You can use the $_FILES superglobal to handle the file upload, establish a database connection using PDO or MySQLi, insert the necessary data into the database, and then store the file path in the database table.

<?php

// File upload handling
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);

// Database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

// Insert data into database
$stmt = $conn->prepare("INSERT INTO table_name (file_path, other_data) VALUES (:file_path, :other_data)");
$stmt->bindParam(':file_path', $target_file);
$stmt->bindParam(':other_data', $other_data);
$stmt->execute();

// Close the database connection
$conn = null;

?>