First of all, sorry if the title has nothing to do with the question, I could not think of anything better. I'm doing a site uploading videos, type a youtube, the person chooses a title and the video file, until then all the html file containing the video and the title and generated however, I save the title in the database and I put the title inside a variable, but when you go to see the title on the page only one of the titles of the database appears, type if the title is "hi" in all the videos the title will be hi, how could I "separate" a title for each video? I had the idea of adding a random id for each die via the upload form but I do not know how to do that.
Upload:
<?php
include("conexao.php");
$msg = false;
if(isset($_FILES['arquivo'])){
$extensao = strtolower(substr($_FILES['arquivo']['name'], -4));
$novo_nome = md5(time()) .$extensao;
$diretorio = "animes/";
$title = $_POST['title'];
move_uploaded_file($_FILES['arquivo']['tmp_name'], $diretorio.$novo_nome);
$sql_code = "INSERT INTO arquivo (codigo, titulo, arquivo, data) VALUES (null, '$title', '$novo_nome', NOW())";
if ($mysqli->query($sql_code))
$msg = "Arquivo enviado. <a href='../criarpg.php?video=".$novo_nome."'>Clique aqui</a> para gerar o HTML";
else
$msg = "Falha ao enviar.";
}
?>
<?php
if ($msg != false) echo "<p> $msg </p>";
?>
Page Generator:
<?php
include("conexao.php");
$link = $_GET['video'];
$pgname = $link.".php";
// pegando titulo
$query = "SELECT titulo FROM arquivo";
$con = $mysqli->query($query) or die($mysqli->error);
while ($row = $con->fetch_array()) {
$pgtitle = $row['titulo'];
}
$arquivo = fopen($pgname, "w");
$texto = "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<title>$pgtitle</title>
</head>
<body>
<h1>$pgtitle</h1>
<center><video src='animes/$link' controls=''></video></center>
</body>
</html>";
fwrite($arquivo, $texto);
?>