-4

This is my code:

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

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

And I'm getting this error:

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

1 Answer 1

0

Use isset() before reading an array key in $_GET/$_POST/$_REQUEST.

$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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.