提问人:hamahara 提问时间:4/25/2020 最后编辑:hamahara 更新时间:4/25/2020 访问量:33
无法弄清楚为什么我为一段代码获得“未定义索引”,而另一段代码却没有
Can't figure out why I'm getting "undefined index" for one section of code but not another
问:
我有几个“多个”选择框,我要从中提取数据。前两个工作正常,但是当我到达第三个时,要么返回 false,要么,如果我把它拿出来,我会收到一个“未定义索引”的通知。isset($_POST('name'))
我尝试复制粘贴代码并更改名称、重新输入、更改 HTML 和 php 中的变量名称。现在我正在用头撞键盘。
html:
<div class = "streamingPlatform">
<label> <span class = "headings"> Streaming Platform </span>
<select name = "platform[]" multiple = "multiple" size = "3">
<option value = "amazon"> Amazon Prime </option>
<option value = "apple"> Apple TV+ </option>
<option value = "crunchy"> CrunchyRoll </option>
<option value = "disney"> Disney+ </option>
<option value = "hbo"> HBO Now </option>
<option value = "hulu"> Hulu </option>
<option value = "netflix"> Netflix </option>
<option value = "showtime"> Showtime </option>
<option value = "starz"> Starz </option>
</select>
</label>
</div>
<div class = "rating">
<label> <span class = "headings"> Rating </span>
<select name = "mpaa[]" multiple = "multiple" size = "3">
<option value = "g"> G </option>
<option value = "pg"> PG </option>
<option value = "pg13"> PG-13 </option>
<option value = "r"> R </option>
<option value = "nc17"> NC-17 </option>
</select>
</label>
</div>
php:
if(isset($_POST['platform']))
$platform = $_POST['platform'];
if(isset($_POST['mpaa']))
$mpaa = $_POST['mpaa'];
目前$platform将返回值,$mpaa不会。如果我在最后一行收到“未定义索引”通知之前删除 from。if(isset($_POST['mpaa']))
$mpaa = $_POST['mpaa'];
要提交给 php 的 HTML:
<form method="POST" action="simpleSearch.php">
<div class = "searchBar">
<p>Search Movies:
<input type="text" name="movie_name" />
<input type = "submit" value = "Search" />
答: 暂无答案
评论
$platform = $mpaa = 'NONE';
echo 'Test: platform = '.json_encode($platform).' / mpaa = '.json_encode($mpaa);