我是一個PHP和編程的完整noob。我對編程非常陌生,所以我的問題可能看起來很愚蠢,但請耐心等待。PHP錯誤:未定義索引:event_list當我認爲它已經定義。
我有一個未定義的索引錯誤,我認爲它已經定義。
我在這裏的代碼。
index.php
<?php include('functions.php'); ?>
<?php
$yr = $_GET['year_list'];
$evnt = $_GET['event_list'];
?>
<html>
<head>
<script type="text/javascript" src="myscripts.js"></script>
</head>
<body>
<div>
<form name="myform" >
Select Year: <?php echo hspacer(1); ?>
<select id="year_list" name="year_list">
<?php
for($year = (date('Y') - 100); $year <= (date('Y') + 100); $year++) {
if ($year == date('Y')) echo "<option value='$year' name='$year' selected='' >" . $year . "</option>";
else echo "<option value='$year' name='$year' >" . $year . "</option>";
}
?>
</select>
<?php echo hspacer(5); ?>
Select Event: <?php echo hspacer(1); ?>
<select id="event_list" name="event_list" >
<?php
$events = array("Karate Tournament", "Beauty Pageant", "Film Festival", "Singing Contest", "Wedding");
foreach($events as $event) echo "<option value='$event' name='$event' >" . $event . "</option>";
?>
</select>
<?php echo vspacer(2); echo hspacer(22); ?>
<input type="submit" id="add_description" name="add_description" value="Add Description" onclick=""/>
</form>
</div>
</body>
</html>
functions.php
<?php
function hspacer($num_of_spaces) {
$spaces = "";
if ($num_of_spaces > 0) for($i=0; $i<$num_of_spaces; $i++) $spaces .= " ";
return $spaces;
}
function vspacer($num_of_linefeeds) {
$linefeeds = "";
if ($num_of_linefeeds > 0) for($i=0; $i<$num_of_linefeeds; $i++) $linefeeds .= "<br />";
return $linefeeds;
}
?>
我不明白這個是什麼,是我認爲當你宣佈一個ID的元素您可以使用該ID作爲索引$_GET
或$_POST
。其次,爲什麼第二個元素(event_list
)與第一個元素(year_list
)具有相同的聲明時無法識別。我對這種不一致感到困惑。只有第二個元素不被識別,而另一個元素被識別。有人可以用簡單的方式向我解釋,像我這樣的初學者可以理解。
使用'的print_r($ _ GET)'和'的print_r($ _ REQUEST)',讓我知道什麼是它打印? – 2011-05-11 10:47:29