PHP development query search to obtain search keywords
Code logic
## 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.
<?php print_r($_GET); ?>Print out the value of get to see if it has been receivedWe then get the entered keyword
<?php $keywords=$_GET['keywords']; echo '查询关键词'.$keywords; ?>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:
- Use get method to obtain data and debug
- Use of isset