vickree Posted July 3, 2008 Share Posted July 3, 2008 Hello, I've created a search using fulltext mysql techniques - and everything is dandy on my personal server - where I test everything. When I transfered it to the server here at my work place - the $search isn't getting substituted correctly... Is this a common error among different versions of PHP on different servers? The code I use is: <!-- Start of Search Function --><br> <br> Please type the name of the product you would like to find. <form method="post" action="search_test.php"> <input type="text" size="30" maxlength="28" name="search"> <input name="submit" type="submit" value="SEARCH!"> </form> <!-- end of search --> <? //Pulling the results for matching words $result = mysql_query ("SELECT image, location, itemName, price FROM `tj_search` WHERE MATCH ( details ) AGAINST ( '$search' ) "); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( "<br><img src=%s/> - <a href=%s> %s</a> - $ %s <br>", $row[0], $row[1], $row[2], $row[3]); } mysql_free_result($result); ?> Again - as I mentioned - this works FINE on my server - but not on the one at work. I ran a test to see if $search is being substituted... but it comes blank. If I change the AGAINST ( '$search' ) "); to one of the keywords - such as uniforms - ALL the uniforms will come up. So it has nothing to do with displaying. Just referencing the variable and pulling the items where the word matches the keywords in the MYSQL table. ANY HELP IS MUCH APPRECIATED. Quote Link to comment Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 It seems that you haven't initialised $search and are relying on register_globals being on - this is bad practice. Try using $_POST['search'] instead of just $search - and tell your host to turn register_globals OFF, it's pure evil. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 3, 2008 Share Posted July 3, 2008 @TransmogriBenno: He has register_globals off on his hosted server but not his personal one. He had better turn it off on his personal one before I explode. =X Quote Link to comment Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 True that, whoops. It should read: tell your host to turn register_globals OFF, it's pure evil. Quote Link to comment Share on other sites More sharing options...
vickree Posted July 3, 2008 Author Share Posted July 3, 2008 <? //Pulling the results for matching words $result = mysql_query ("SELECT image, location, itemName, price FROM `tj_search` WHERE MATCH ( details ) AGAINST ( $_POST['search'] ) "); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( "<br><img src=%s/> - <a href=%s> %s</a> - $ %s <br>", $row[0], $row[1], $row[2], $row[3]); } mysql_free_result($result); ?> Im getting an error on like 110 - which is $_POST['search'] Am sure im probably missing something completely stupid.... Quote Link to comment Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 When including a variable in a string, you should enclose it in {}. If the variable is an array element, you must enclose it. Also, you removed the quotes around the match term, which is an SQL string and needs the quotes. So perhaps AGAINST ( '{$_POST['search']}' ) "); Instead of AGAINST ( $_POST['search'] ) "); Quote Link to comment Share on other sites More sharing options...
vickree Posted July 3, 2008 Author Share Posted July 3, 2008 THANK YOU THANK YOU THANK YOU! It's working now! Thanks everyone for your help! :D :D Quote Link to comment 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.