Created
May 18, 2021 17:43
-
-
Save DaniloCeesar/95c63e7c93e56deb05fb150923d03fe8 to your computer and use it in GitHub Desktop.
Search form example using GET request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Search form example</title> | |
</head> | |
<body> | |
<form method="GET" id="websearch" name="websearch" action="search_target.php"> | |
<label for="q">Search query:</label> | |
<input type="text" id="q" name="q"> <br /> | |
<button type="submit">Search</button> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Beforehand, check if there's any query informed by the user; if not, then show an error message, and abort all the functions | |
if ( empty($_GET["q"]) ) { | |
die("User did not inform any query."); | |
} | |
// Here goes your database query functions | |
// [...] | |
// Prints the search query on the page | |
echo( | |
'Search results for "' . htmlspecialchars($_GET["q"], ENT_QUOTES, "UTF-8") . '":' | |
); | |
// Prints the search results | |
// [...] | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment