3raser Posted January 11, 2011 Share Posted January 11, 2011 http://minecraftservers.comyr.com/search.php <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php echo "<a href='../index.php'>Home</a> | <a href='start_upload.php'>Upload</a> | Search & Browse | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $search = $_POST['search']; if(!$search) { echo "<form action='search.php' method='POST'>Search: <input type='text' name='search'><input type='submit' value='Search'></form>"; } else { $query = mysql_query("SELECT * FROM mods WHERE name LIKE '%$search%' OR description LIKE '%$search%'"); while ($row = mysql_fetch_assoc($query)) { $x++; echo "#". $x .": ". $row['name'] .".[VIEW]<br/>"; } if($x=="0") { echo "No results found."; } else { echo "<br/>".$x." results."; } } include("includes/footer.php"); ?> Whenever you type in something without spaces, it works perfectly. When you do add a space, it basically goes blank. :/ Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/ Share on other sites More sharing options...
denno020 Posted January 11, 2011 Share Posted January 11, 2011 you will need to cleanse the search data, to make sure php doesn't interpret the spaces as anything other than a space. I can't think of the functions of the top of my head, but a simple google search should find something you need. It will convert spaces into   (I believe). So look into cleansing of input text. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1157736 Share on other sites More sharing options...
3raser Posted January 11, 2011 Author Share Posted January 11, 2011 you will need to cleanse the search data, to make sure php doesn't interpret the spaces as anything other than a space. I can't think of the functions of the top of my head, but a simple google search should find something you need. It will convert spaces into   (I believe). So look into cleansing of input text. Denno Doesn't that nbsp function add a space? If so, how do this help? The code already has a space when someone types in a space manually. Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1158104 Share on other sites More sharing options...
BlueSkyIS Posted January 11, 2011 Share Posted January 11, 2011 no, do not replace spaces with the html entity unless you expect to actually be in the data. $search = (isset($_POST['search']))?$_POST['search']:false; if(!$search) { echo "<form action='search.php' method='POST'>Search: <input type='text' name='search'><input type='submit' value='Search'></form>"; } else { if (get_magic_quotes_gpc()) { $search = stripslashes($search); } $search = mysql_real_escape_string($search); $sql = "SELECT * FROM mods WHERE name LIKE '%$search%' OR description LIKE '%$search%'"; $query = mysql_query($sql) or die(mysql_error()); // Now, loop over results. } updated to replace $result with $query Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1158108 Share on other sites More sharing options...
3raser Posted January 12, 2011 Author Share Posted January 12, 2011 no, do not replace spaces with the html entity unless you expect to actually be in the data. $search = (isset($_POST['search']))?$_POST['search']:false; if(!$search) { echo "<form action='search.php' method='POST'>Search: <input type='text' name='search'><input type='submit' value='Search'></form>"; } else { if (get_magic_quotes_gpc()) { $search = stripslashes($search); } $search = mysql_real_escape_string($search); $sql = "SELECT * FROM mods WHERE name LIKE '%$search%' OR description LIKE '%$search%'"; $query = mysql_query($sql) or die(mysql_error()); // Now, loop over results. } updated to replace $result with $query Still does the same glitch, and I updated my code accordingly. <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php echo "<a href='../index.php'>Home</a> | <a href='start_upload.php'>Upload</a> | Search & Browse | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $search = (isset($_POST['search']))?$_POST['search']:false; if(!$search) { echo "<form action='search.php' method='POST'>Search: <input type='text' name='search'><input type='submit' value='Search'></form>"; } else { if (get_magic_quotes_gpc()) { $search = stripslashes($search); } $search = mysql_real_escape_string($search); $sql = "SELECT * FROM mods WHERE name LIKE '%$search%' OR description LIKE '%$search%'"; $query = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($query)) { $x++; echo "#". $x .": ". $row['name'] .".[VIEW]<br/>"; } if(!$x) { echo "No results found."; } else { echo "<br/>".$x." results."; } } include("includes/footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1158153 Share on other sites More sharing options...
denno020 Posted January 12, 2011 Share Posted January 12, 2011 Doesn't that nbsp function add a space? If so, how do this help? The code already has a space when someone types in a space manually. All I said was this is what I think the cleansing functions will do. Read more carefully and don't assume things. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1158205 Share on other sites More sharing options...
litebearer Posted January 12, 2011 Share Posted January 12, 2011 One supposes you could break "joe shmoo" into 2 search words or "Gomer Pyle Marine" into 3 and adjust your query accordingly (How? explode using space as delimiter, count the elements and loop thru adding to your query) Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1158212 Share on other sites More sharing options...
3raser Posted January 12, 2011 Author Share Posted January 12, 2011 Doesn't that nbsp function add a space? If so, how do this help? The code already has a space when someone types in a space manually. All I said was this is what I think the cleansing functions will do. Read more carefully and don't assume things. Denno How about don't be an ass? Quote Link to comment https://forums.phpfreaks.com/topic/224041-search-result-turns-nothing-with-space/#findComment-1158572 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.