<pre><?php
session_start();
header("Content-Type: application/json;charset=utf-8");
if (!isset($_SESSION['id_usuario'])) {
echo json_encode(["status" => false, "msg" => "Debes iniciar sesión para publicar un episodio"]);
exit;
}
require "../../img_upload_script.php";
require "../../audio_upload_script.php";
$json = $_POST["json"];
if (empty($json)) {
echo json_encode(["status" => false, "msg" => "No se han proporcionado los datos necesarios"]);
exit;
}
$data = json_decode($json);
$link = new mysqli('localhost', 'root', '', 'madradio', 3306);
$stmt = $link->prepare("INSERT INTO publicaciones (titulo, descripcion, etiquetas, id_categoria, id_genero, id_usuario, url_imagen, url_audio, fecha) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssiiisss", $data->titulo, $data->descripcion, $data->etiquetas, $data->id_categoria, $data->id_genero, $_SESSION["id_usuario"], $target_file_image, $target_file_audio, date('Y-m-d'));
$stmt->execute();
if ($stmt->affected_rows <= 0) {
$stmt->close();
$link->close();
echo json_encode(["status" => false, "msg" => "No se ha creado la publicación"]);
exit;
}
$stmt->close();
$link->close();
echo json_encode(["status" => true, "msg" => "Publicación creada con éxito"]);
What I have tried:
Hello good evening,
I have a problem with the code I posted and have been sitting for hours to find the solution but I am not able to find the bug, everything in the code looks good to me I've revised every comma and the problem is in the bind_param section. Any help is much appreciated