我目前正在使用文本文件,并将其内容写入列表。在列表中,我只是使用 GET 参数来接收列表中所选链接的值。当我点击选择的链接时,我想写下链接的值。情况是列表还在,值写在它下面。我该如何解决这个问题?我需要列表消失,只显示所选链接的名称。我使用 if 语句,但它不起作用。
<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
if(!isset($readin)){
$readin = file('filmer.txt');
$ul = '<ul id="films">';
echo $ul;
foreach($readin as $fName){
$lineSplit = explode(";", $fName);
if(isset($lineSplit[1])){
echo '<li>'.'<a href="Filmer-PHP.php?name=' .$lineSplit[0]. '">'.$lineSplit[0].'<span>'.$lineSplit[1].'</span>'.'</a>'.'</li>';
}
}
}
?>
<?php
// Läsa av och visa detaljerad info om filmer
if(isset($_GET['name'])){
$name = $_GET['name'];
$readin = file('filmer.txt');
foreach($readin as $fName){
$lineSplit = explode(";", $fName);
$lineSplit[0] = $name;
}
echo $lineSplit[0];
}
?>
</div>
<?php
include("footer.php");
?>
</div>
</body>
</html>