我正在处理一个表格,我在其中写下有关电影的信息,然后将其发布到文本文件中。然后我在列表中回显它,链接到同一个文件。我知道要给链接一个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>
答案 0 :(得分:2)
单引号中的变量未展开,因此如果您这样写:
echo '<a href="Filmer-PHP.php?filmer=$lineSplit[0]">'
这将最终成为
<a href="Filmer-PHP.php?filmer=$lineSplit[0]">
您可能希望$ lineSplit [0]替换为该变量的值。使用双引号
echo "<a href='Filmer-PHP.php?filmer=$lineSplit[0]'>"
或将其置于引号之外
echo '<a href="Filmer-PHP.php?filmer=' . $lineSplit[0] . '">'