运行代码时,我不断收到此通知:
Notice: Undefined offset: 1 in C:\Users\Walid\xampp\htdocs\Inl3\Filmer-PHP.php on line 83
它在这条线上抱怨:
echo '<li>'.'<a href="Filmer-PHP.php?name=' .$lineSplit[0]. '">'.$lineSplit[0].'<span>'.$lineSplit[1].'</span>'.'</a>'.'</li>';
我认为它在 $lineSplit[1] 上抱怨。我真的不知道为什么它会抱怨,尽管代码工作正常,因为它是一个通知。但它出现在我的屏幕上,我不知道如何解决它。
完整代码:
<!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?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');
$lineSplit = explode(";", $name);
echo $name;
}
?>
</div>
<?php
include("footer.php");
?>
</div>
</body>
</html>