Hi,

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:

'%:substring%'

Any help would be much apprieciated.

Hi,
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.

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.