Issue
This is an example of: When php cant work in some websites.
I was trying to make a Search_Query
but it doesn’t work. Even inspect element
doesn’t work. They made the code like:
<!--<?php echo "hello" ?>-->
i do not know why but it happens.
here’s my files:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Home - Yantoxsoft</title>
<!-- Load external CSS styles -->
<link rel="stylesheet" href="styles.css">
<!-- Load website icon -->
<link rel='shortcut icon' href='icon.jpeg'>
</head>
<body>
<form action='search.html'>
<label for='search_query'>
Search:<input name='search_query'><input type="submit">
</label>
</form>
<!-- Load external JavaScript -->
<script src="scripts.js"></script>
</body>
</html>
<form action='search.html' method='POST'>
<label for='search_query'>
<input name='search_query'>
</label>
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$search = $_POST['search_query'];
if (empty($search)) {
echo "No Results for: " + $search;
} else {
echo "results for:" + $search;
}
}
?>
and do not answer with .php
files because they are not supported :/
Because they only make .css
, .js
, and .html
files and image or gif files. Why not python
, lua
, mp4
, or php
? Who knows.
Solution
Please save PHP file with .php extension and use html tag inside as: echo "<h1>Hello Dev!</h1>";
i.e after saving your code in .php format
<?php
echo "<form action='search.html' method='POST'>
<label for='search_query'>
<input name='search_query'>
</label>
</form>";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$search = $_POST['search_query'];
if (empty($search)) {
echo "No Results for: " + $search;
} else {
echo "results for:" + $search;
}
}
?>
Answered By – Adigun Akorede Rasheed
Answer Checked By – Marilyn (AngularFixing Volunteer)