PHP development query search to obtain search keywords

Code logic

QQ截图20161201142717.png

## Search keyword

We first create a form to submit the search.

<!DOCTYPE html>
 <html>
 <head>
     <meta charset="UTF-8">
     <title>查询器</title>
 </head>
 <body>
 <form action="" method="get">
     <p><input type="text" name="keywords"  value="" placeholder="请输入内容"/>
     <p><input type="submit"  value="查询"/>
 </form>
 </body>
 </html>

We use the get submission method to submit.

QQ截图20161105111259.png

<?php
print_r($_GET);
?>

Print out the value of get to see if it has been received

QQ截图20161105111652.png

We then get the entered keyword

<?php
$keywords=$_GET['keywords'];
echo '查询关键词'.$keywords;
?>

QQ截图20161105112256.png

We found that if the input is empty, the query data will be very troublesome. What should we do in order to avoid this wrong operation.

$keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';

Remove spaces on both sides, otherwise it is empty.


Difficulties in this chapter:

  1. Use get method to obtain data and debug

  2. Use of isset

Continuing Learning
||
<?php $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : ''; echo '查询关键词'.$keywords; ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询器</title> </head> <body> <form action="" method="get"> <p><input type="text" name="keywords" value="" placeholder="请输入内容"/> <p><input type="submit" value="查询"/> </form> </body> </html>
submitReset Code