i am able to store all fields except $binarydata it keeps saving as an empty cell in the database. i had working code before and saw the track image column light up with a BLOB data BUT NOW for some reason it wont insert the BLOB. any help would be greatly appreciated
if (isset($_POST['submit'])) {
// Taking all 4 values from the form data(input)
$trackname = $_POST['trackname'];
$descr = $_POST['descr'];
$tags = $_POST['tags'];
$genre = $_POST['genre'];
$artist = $username;
// Check if a file was uploaded successfully
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
// Get the temporary file name
$file_tmp = $_FILES['file']['tmp_name'];
// Open the file in binary mode and read the data
$binaryData = file_get_contents($file_tmp);
} else {
// If no file was uploaded or an error occurred, set $binaryData to NULL
$binaryData = NULL;
}
// Performing insert query execution
// Here, we explicitly specify the columns we are inserting into (excluding user_id)
$sql = "INSERT INTO tracks (trackname, descr, tags, genre, artist,trackimage) VALUES (?, ?, ?, ?, ?, ?)";
// Prepare the SQL statement
$stmt = mysqli_prepare($conn, $sql);
if ($stmt === false) {
// Handle the error if the statement preparation fails
die("ERROR: Could not prepare the SQL statement. " . mysqli_error($conn));
}
// Bind the parameters to the statement, "b" is used for BLOB data
mysqli_stmt_bind_param($stmt, "sssssb", $trackname, $descr, $tags, $genre, $artist, $binaryData);
$stmt->send_long_data(1, $binaryData);
// Execute the statement
if (mysqli_stmt_execute($stmt)) {
$stmt->execute(
FIXED:
// Check if a file was uploaded successfully
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
// Get the temporary file name
$file_tmp = $_FILES['file']['tmp_name'];
// Open the file in binary mode and read the data
$binaryData = fopen($file_tmp, 'rb');
// Get the contents of the file as a string
$file_contents = fread($binaryData, filesize($file_tmp));
mysqli_stmt_send_long_data($stmt, 5, $file_contents);