I have a php file that contains the queries as strings. I have wrote the following query:

SELECT message_no, sender, destination, time_received, type, reference_no, message
FROM messages
WHERE message LIKE '%:substring%';

:substring is then assigned a value from $substring.

The query works when i run it directly in cmd however it does not work within the php web application.
All messages with the substring value within $substring should be displayed.

I believe there must be a problem with this part:


Any help would be much apprieciated.

Re: SQL Query in PHP not working 80 80

I am learning php as probably you. I think that you need to use sprintf to format the string after LIKE. See:
Click Here
Please, forgive me if I am wrong.

Re: SQL Query in PHP not working 80 80

I am not sure what the : is for but to do what you want, it should be:

WHERE message LIKE '."'%$substring%'".';
Be a part of the DaniWeb community

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