MySQL Like Query
I currently have the following code
$sql = "select * from messages where id = '".$_POST['id']."' or from = '". $_POST['from'] ."' or subject = '". $_POST['subject'] ."' or message = '". $_POST['message'] ."' ORDER BY id DESC";
What I would like to do is have a LIKE on subject and message, non-case sensitive but not sure how to do it?
Can someone tell me how?
Ok I have it sort of working
$sql = "select * from messages where id = '".$_POST['id']."' or from = '". $_POST['from'] ."' or subject LIKE '%". $_POST['subject'] ."%' or message LIKE '%". $_POST['message'] ."%' ORDER BY id DESC";
But the problem is when I do a from search it comes back with all sorts, which I have tracked down to subject and message being blank on the search page.
How can I make sure that subject and message has something when doing the query?
||04-28-2013 10:37 PM
Heard of the if
statement in PHP?
$msg = "" . $_POST["message"];
$subj = "" . $_POST["submect"];
if ( strlen($msg) == 0 || strlen($subj) == 0 )
echo "No message or no subject given. Aborting.";
exit( "Invalid request" );
... continue ...
|All times are GMT +1. The time now is 01:40 PM.
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.