Forum Moderators: coopster
In MySql database I store the restaurant names like "My Restaurant & Bar"
On the website before people can add a new restaurant they must search for that restaurant to make sure it does not already exists in the database.
The problem is that when people search for "My Restaurant & Bar" the restaurant "My Restaurant & Bar" that already exists is not found.
How can I solve this issue? any ideas?
Thank you
You can use htmlentities on the search string before you use it in the query:
#connect to db server, select db all here
$search = [url=http://us2.php.net/mysql-real-escape-string]mysql_real_escape_string[/url]([url=http://us2.php.net/htmlentities]htmlentities[/url]($_POST['search']));
#run query
You might also want to check the spaces as they may be different.
Good luck! :)
In MySql database I store the restaurant names like "My Restaurant & Bar"
As a side note, why not store the plain text in the database? Why store the htmlentities version? That way, if you ever want to view it outside of HTML it can be read normally. This may not seem evident right now, but it sure will as soon as you try to use the text in something other than HTML format, like perhaps a plain text email, a PDF document, or even just viewing it from the command line.
I find it easier to store the data text normally, as in plain text, as opposed to formatting it for some particular output. Format it when you pull it out instead. Just a consideration for you.