insert.php
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rögzités</title>
</head>
<body>
<form action="insert.php" method="POST">
<input type="text" placeholder="Cim" name="cim">
<input type="text" placeholder="Eredeti" name="eredeti">
<input type="number" placeholder="Év" name="ev">
<input type="text" placeholder="Rendező" name="rendezo">
<input type="text" placeholder="Magyar szöveg" name="magyarszoveg">
<input type="text" placeholder="Szinkron rendező" name="szinkronrendezo">
<input type="text" placeholder="Stúdió" name="studio">
<button type="submit">Rögzít</button>
</form>
<?php
require "database.php";
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(
empty($_POST['cim']) &&
empty($_POST['eredeti']) &&
empty($_POST['ev']) &&
empty($_POST['rendezo']) &&
empty($_POST['magyarszoveg']) &&
empty($_POST['szinkronrendezo']) &&
empty($_POST['studio'])
){
echo "Hiányos adatok!";
}else{
$incQuery = "SELECT filmaz FROM `film`
ORDER BY `filmaz` DESC limit 1;";
$incStmt = mysqli_prepare($conn, $incQuery);
mysqli_stmt_execute($incStmt);
$result = mysqli_stmt_get_result($incStmt);
$result = $result->fetch_assoc();
$newID = $result["filmaz"]+1;
$query = "INSERT INTO `film`(`filmaz`, `cim`, `eredeti`, `ev`, `rendezo`, `magyarszoveg`, `szinkronrendezo`, `studio`)
VALUES ('{$newID}','{$_POST['cim']}','{$_POST['eredeti']}','{$_POST['ev']}','{$_POST['rendezo']}','{$_POST['magyarszoveg']}','{$_POST['szinkronrendezo']}','{$_POST['studio']}')";
$stmt = mysqli_prepare($conn, $query);
if(mysqli_stmt_execute($stmt)){
echo "Adatok felvitele sikeres!";
header("Location: index.php");
}else{
echo "Adatok felvitele sikertelen!";
}
}
}
?>
</body>
</html>
index.php
table {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 50%;
}
th, td {
border: 3px solid #AAAAAA;
padding: 5px;
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="index.php" method="POST">
<input type="text" name="txt" required>
<input type="submit" value="Keresés">
</form>
<a href="insert.php">Új film rögzitése</a>
</body>
</html>
<?php
if(isset($_POST["txt"])){
require "database.php";
$txt = "%" . strtoupper($_POST["txt"]) . "%";
$sql = "SELECT * FROM film WHERE UPPER(cim) LIKE ?";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "s", $txt);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
echo "<table id='tb'>";
if (mysqli_num_rows($result) > 1) {
echo "Nem egyértelmű szűrés!";
} else if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$cim = $row["cim"];
$eredeti = $row["eredeti"];
$ev = $row["ev"];
$filmaz = $row["filmaz"];
echo "<h1>$cim ($eredeti) - $ev</h1>";
$sql2 = "SELECT szerep, szinesz, hang FROM szinkron WHERE filmaz = ?";
$stmt2 = mysqli_prepare($conn, $sql2);
mysqli_stmt_bind_param($stmt2, "s", $filmaz);
mysqli_stmt_execute($stmt2);
$result2 = mysqli_stmt_get_result($stmt2);
if (mysqli_num_rows($result2) > 0) {
$row2 = mysqli_fetch_assoc($result2);
$szerep = $row2["szerep"];
$szinesz = $row2["szinesz"];
$hang = $row2["hang"];
echo "<tr> <th>$szerep</td> <th>$szinesz</td> <th>$hang</td> <tr>";
echo "</table>";
} else {
echo "Nincs szinkron találat!";
}
} else {
echo "</br>Nincs találat!";
}
;
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
?>
database
$conn = mysqli_connect("localhost", "root", "", "szinkronhangok");
if (!$conn) {
die("Nem sikerült csatlakozni!");
}
?>