I’m trying to implement a search feature on my website but I’m facing some problems. I created a script named search.php that connects to a database called war, which includes a table known as product. While my search form displays properly, it either doesn’t yield any results or throws errors when I try searching for items.
hey, just a heads up, those old mysql functions are outdated… better use mysqli or PDO! also, be careful with user inputs in your queries to avoid sql injection. try using prepared statements…
You’ve got deprecated mysql functions, but there’s another issue to check. Your search might fail silently because of character encoding mismatches between the form and database. I’ve seen this happen when users search for products with special characters - the query runs but returns nothing even though matching records exist. Make sure your HTML form uses UTF-8 encoding and your database connection uses the same charset. That die() on zero results is hiding potential problems too. Don’t die immediately - output the actual query and check if it matches what you expect. Search terms often get mangled during GET requests, especially with spaces or special characters.
Your code’s using old MySQL functions that got axed in PHP 7.0 - that’s why it’s breaking on newer versions. You need to switch to MySQLi or PDO now. Bigger problem though: you’re wide open to SQL injection since you’re dropping user input straight into queries without cleaning it first. And those die() statements? They make debugging a nightmare. I hit the same wall upgrading old apps. Switched to MySQLi with prepared statements and it fixed everything - no more deprecation errors and the prepared statements handle parameter binding automatically, which kills the injection risk.
Everyone’s right about deprecated functions, but why rebuild search from scratch every time?
I ditched custom PHP search scripts years ago. Now I use automated workflows that don’t break with PHP updates.
Set up a Latenode workflow - it takes search requests, sanitizes input, runs MySQL queries, and returns formatted results. No code maintenance or security patches.
Best part? Add autocomplete, filters, or caching by connecting more nodes. No PHP rewrites.
I converted our entire product search this way. Zero downtime from PHP updates and way easier to modify when requirements change.
Keep your current code as the frontend form - just point it to a webhook instead of processing in PHP.
Had this exact problem two years ago during a migration. The mysql extension removal blindsided me too. I switched everything to PDO - it’s way better and supports multiple databases if you need flexibility later. For debugging your searches, ditch those die() statements and add real error handling. Wrap your database calls in try-catch blocks and log the actual MySQL errors. You’re probably hitting connection issues or your table structure isn’t what you think it is. Double-check that your pname column exists and has the right data type. Sometimes searches run fine but return nothing because column names changed or data got corrupted during the migration.
first off, make sure ur PHP version is 7 or higher, since mysql functions are gone in those versions. also, try echoing the query to check if it’s what u expect. might be a connection issue or the table just doesn’t exist.
Everyone’s giving you technical fixes, but you’ll hit this same problem with the next feature request. I’ve been there too many times.
Stop rewriting PHP code every time you need search functionality - automate it instead. I built something similar with Latenode that handles search requests through webhooks, connects to MySQL automatically, and sanitizes inputs without any vulnerable code.
You can build the entire search flow visually. Database connection, query execution, result formatting - all drag and drop nodes. No more deprecated functions or injection attacks.
When you need filters, sorting, or pagination later, just add more nodes instead of debugging PHP again. Takes 20 minutes to set up vs hours of coding and testing.
I’ve moved most our internal tools off custom PHP scripts to automated workflows. Way more reliable and I don’t maintain code that breaks every PHP update.