-2

I'm trying to make a simple search engine (currently using 10 random html files I've made) but I can't get the php echo to tell me I search results (which I'm using to verify that the php file knows what the search query is.) I tried using just php

This V

<?php echo $_GET["query"]; ?>

I tried PHP in HTML

<html>
<body>

<p> Search: </p> <?php echo $_GET["query"]; ?><br>

</body>
</html>

But none if it worked. Here's the code for the HTML file.

<html>
    <head>
        <title>Search Test</title>
    </head>
    <body>
        <form action="Searching.php" method="post">
            Search: <input type="text" name="query">
            <input type="submit">
        </form>
    </body>
</html>

When you run the search engine and type your query the php files shows up just showing the contents of the php file. (If its an html file with php in it its just "Search:" so the query isn't showing.) I expect it to just show what my search query was.

Slothscript
  • 103
  • 9

1 Answers1

0

Since you’re sending the form over POST, you would need to use $_POST instead of $_GET.

Also, your current implementation is vulnerable to cross-site scripting. You should use htmlspecialchars when you echo content you cannot trust.

Nicolapps
  • 819
  • 13
  • 29
  • That still didn't work. I added the $_POST() but it just changed the part where it just said $_GET() to $_POST() – Slothscript Nov 23 '22 at 16:02