Hi,
Currently I am building a html page that has some fields to search items into database.
For the moment I am using 2 files index.html and search.php, in the page index.html I can input the word that I want
to search in the database and I send the inputs to the search.php file that it gives me the results in a table...
But here its the problem! This is a ugly way to do this.

Could anyone help me with an example how to make a seach page(.html) that interacts with a .php file, but it shows
the results on its page.

Dani AI

Generated

A clean, single-page result flow is best done with an XHR/fetch pattern: have the existing search.php act as an API and update the HTML table on the client. was right to point toward Ajax; two common server responses work well in practice — JSON (preferred) or pre-rendered HTML snippets. Keep the original form action as a graceful fallback so non-JS browsers still get full-page results.

Client-side workflow (high level): prevent the form's full submit, show a small loading state, send the form data to search.php with fetch or XHR, parse the response, then rebuild the table rows from safe text nodes (use textContent or templates, avoid raw innerHTML with unescaped data). Server-side workflow: validate and sanitize inputs, use parameterized queries (PDO or mysqli prepared statements), limit results with LIMIT/OFFSET for paging, and return structured JSON with a rows array plus metadata like total and page.

Practical UX and performance tips: debounce input when doing live search, add server-side pagination for large datasets, return only the needed columns (avoid SELECT *), and keep a visible result count/empty-state message. Use history.pushState if result URLs should be bookmarkable. For accessibility, ensure the table has proper headers and use an aria-live region for result status updates.

Security/caveats: never interpolate raw database strings into HTML without escaping (use PHP htmlspecialchars when returning HTML); prefer JSON + client-side escaping. Ensure the search endpoint uses prepared statements to prevent SQL injection, and test network responses in browser devtools to confirm correct Content-Type and HTTP status codes. As noted, a working script already appeared later in the thread — confirm that solution follows these safety and UX practices before deploying.

Recommended Answers

All 7 Replies

You would like to show the results on the same HTML page? Without any server side scripting on that HTML page, you can use JavaScript/Ajax to get results back from the web server.

Here are the files that I use. Could you modify them to work the way that I want?

PHP is not my strength. I have more expereince with asp.net. We'll need someone else to assist you with PHP guidance.

Thx man, however in my opinion this is a child stuff, but I am a begginer in web programming so I don't understand very well this things...

you are correct in your assumption. What you are asking is very basic.

The concept as I understand what you are asking is that you want to provide search capability from index.html and provide the results on the same page.

You can do this via Ajax.

Here is an example pretty close to your scenarion but is shown with a asp page. Instead of asp, your back-end page is the search.php page.

Good to hear!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.