【问题标题】:Undefined index: search in C:\wamp\www\search1 (2).php on line 4 [duplicate]未定义的索引:在第 4 行的 C:\wamp\www\search1 (2).php 中搜索 [重复]
【发布时间】:2015-06-01 11:47:50
【问题描述】:

这是我的代码:

$button = $_GET ['submit'];
$search = $_GET ['search']; 

if(!$button)
echo "you didn't submit a keyword!";
else

我收到了这个错误:

Undefined index: search in C:\wamp\www\search1 (2).php on line 4

【问题讨论】:

标签: php


【解决方案1】:

在读取 $_GET/$_POST/$_REQUEST 中的数组键之前使用 isset()。

$button = isset($_GET['submit']) ? $_GET['submit'] : false;
$search = isset($_GET['search']) ? $_GET['search'] : false;
if(!$button) echo "you didn't submit a keyword!";

PHP Undefined Index

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 2016-04-03
    • 2012-12-13
    • 1970-01-01
    • 2016-10-09
    • 2013-06-17
    • 1970-01-01
    • 2018-03-14
    相关资源
    最近更新 更多