Skip to content
Advertisement

Search form with PDO

The below code now works but how can I make it so if no results are found it echos a message instead of blank.

I think I’ve managed to create a search query for my database. Its only a very basic search but it doesn’t seem to work for some reason. Any advice would be appreciated im still new to pdo (very new! be kind!).

Also no user submitted data is inserted into the database so I think i can rule out xss assuming its SQL inject free? Which from what I understand PDO is? plus im using a stand alone DB user with no write access.

Have replace data with xxx for security

file is called search.php

*updated to reflect changes suggested *2nd update to reflect help provided *3rd update

JavaScript

Advertisement

Answer

The problem is in the form. the method is GET but in your php you expect $_POST

So this line:

JavaScript

should be:

JavaScript

UPDATE

Change your code to this:

JavaScript

To check if there are no line and give a message you can do it like this:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement