我正在编写一个表单,我在其中编写有关电影的信息,并将其发布到文本文件中。然后我在一个列表中回显它,其中包含指向同一文件的链接。我知道要给链接一个 GET 参数,以便选择的链接名称作为 GET 参数发送。我似乎无法正确处理。
<!DOCTYPE html>
<html>
<head>
<title>Inlämning3</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jQuery.js" >
</script>
<script type="text/javascript" src="valideraFilmer.js" >
</script>
</head>
<body>
<?php
// Skriva film och info till en textfil
if( isset ($_POST['name'])){
$name = $_POST['name'];
$grade = $_POST['options'];
$link = $_POST['link'];
$pic = $_POST['pic'];
$story = $_POST['story'];
$myFile = "filmer.txt";
$handle = fopen($myFile, 'a');
if(!empty($name)){
fwrite($handle, $name. ";");
fwrite($handle, $grade. ";");
fwrite($handle, $link. ";");
fwrite($handle, $pic. ";");
fwrite($handle, $story. "\n");
fclose($handle);
}
}
?>
<div id="page">
<?php
include("header.php");
?>
<div id="leftbar">
<form id="form" method="post" action="Filmer-PHP.php" >
<fieldset>
<legend>Lägg till en film:</legend>
Titel:
<br><input type="text" name="name" id="name"><br>
Betyg:
<br><select id="options" name="options">
<option value="0">Välj betyg här...</option>
<option value="*"> *</option>
<option value="**"> **</option>
<option value="***"> ***</option>
<option value="****"> ****</option>
<option value="*****"> *****</option>
</select>
<br>
Länk till imdb:
<br><input type="text" name="link" id="link"><br>
Länk till bild:
<br><input type="text" name="pic" id="pic"><br>
Filmens handling:
<br><textArea cols="20" rows="3" name="story" id="story"></textarea><br>
<br><input type="submit" name="button" value="Spara film" id="button">
</fieldset>
</form>
</div>
<div id="rightbar">
<h2>Filmer</h2>
<?php
// Läsa av och visa titel och betyg
$readin = file('filmer.txt');
$ul = '<ul id="films">';
echo $ul;
foreach($readin as $fName){
$lineSplit = explode(";", $fName);
echo '<li>'.'<a href="Filmer-PHP.php?filmer=$lineSplit[0]">'.$lineSplit[0].'<span>'.$lineSplit[1].'</span>'.'</a>'.'</li>';
}
?>
<?php
// Läsa av och visa detaljerad info om filmer
?>
</div>
<?php
include("footer.php");
?>
</div>
</body>
</html>