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.
CodePudding user response:
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;
}
}
?>
CodePudding user response:
Your HTML files won't be processed by PHP engine but You've saved everything in an html file so it's clear why it doesn't work.
Change the extension from .html
to .php
and if your hosting service provider doesn't support PHP, you have to find another one.
CodePudding user response:
A PHP Script will never work in a file with .html
extension. You already said your hosting provider doesn't allow .php
. You don't have any other problem. You either forget about your search functionality or change your host!