cs1h Posted September 24, 2007 Share Posted September 24, 2007 Hi, I'm not very good with php and can't see whats wrong with the following piece of code $sql = "SELECT * FROM items WHERE (country='" . mysql_real_escape_string($targetb)" OR continent='" . mysql_real_escape_string($targetb) . "') AND type='" . mysql_real_escape_string($_POST['Type']) . "' AND (Abstract LIKE '%$keyword%' OR town LIKE '%$keyword%') ORDER BY id DESC"; Does anyone know why it doesn't work Cheers Colin Quote Link to comment https://forums.phpfreaks.com/topic/70488-solved-search-problem/ Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2007 Share Posted September 24, 2007 what doesn't work? is there an error message? if you do mysql_query($sql) or die(mysql_error()), what is the error? Quote Link to comment https://forums.phpfreaks.com/topic/70488-solved-search-problem/#findComment-354092 Share on other sites More sharing options...
Fadion Posted September 24, 2007 Share Posted September 24, 2007 A better looking and simple to debug code should be: $targetb = mysql_real_escape_string($targetb); //or post or get data or whatever $type = mysql_real_escape_string($_POST['Type']); $sql = "SELECT * FROM items WHERE (country='$targetb' OR continent='$targetb') AND type='$type' AND (abstract LIKE '%$keyword%' OR town LIKE '%$keyword%') ORDER BY id DESC"; $results = mysql_query($sql) or die(mysql_error()); Note the "or die(mysql_error())", it should bring up the error caused. See what error ure getting. Quote Link to comment https://forums.phpfreaks.com/topic/70488-solved-search-problem/#findComment-354093 Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2007 Share Posted September 24, 2007 yes, and you'll probably find the error is here: WHERE (country='" . mysql_real_escape_string($targetb)" OR you're missing . and ' Quote Link to comment https://forums.phpfreaks.com/topic/70488-solved-search-problem/#findComment-354098 Share on other sites More sharing options...
cs1h Posted September 24, 2007 Author Share Posted September 24, 2007 Hi, I changed it to $targetb = $_POST['menuFilesDMA']; $targetb = str_replace(' ','_', $targetb); $targetb = mysql_real_escape_string($targetb); $type = mysql_real_escape_string($_POST['Type']); mysql_connect("localhost","adder","clifford"); mysql_select_db("real") or die("Unable to select database"); $keywords = preg_split("/[\s,]+/", trim($_POST['keyword'])); $sql = "SELECT * FROM items WHERE (country='$targetb' OR continent='$targetb') AND type='$type' AND (abstract LIKE '%$keyword%' OR town LIKE '%$keyword%') ORDER BY id DESC"; $result = mysql_query($sql) or die(mysql_error()); and now I get the error, Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Inetpub\vhost\myroho.com\httpdocs\absearch.php on line 5 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\Inetpub\vhost\myroho.com\httpdocs\absearch.php on line 5 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Inetpub\vhost\myroho.com\httpdocs\absearch.php on line 7 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in D:\Inetpub\vhost\myroho.com\httpdocs\absearch.php on line 7 Any ideas why this is, Thanks for all the help, Colin Quote Link to comment https://forums.phpfreaks.com/topic/70488-solved-search-problem/#findComment-354102 Share on other sites More sharing options...
sayedsohail Posted September 24, 2007 Share Posted September 24, 2007 Move the following lines under the mysql connect statement i.e, mysql_connect("localhost","adder","clifford"); mysql_select_db("real") or die("Unable to select database"); $targetb = mysql_real_escape_string($targetb); $type = mysql_real_escape_string($_POST['Type']); This should solve your problem. good luck. Quote Link to comment https://forums.phpfreaks.com/topic/70488-solved-search-problem/#findComment-354283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.