madsovenielsen Posted March 31, 2010 Share Posted March 31, 2010 I have this PHP and SQL <?php$conn = mysql_connect('localhost', 'root', '**********');mysql_select_db("bookmarks", $conn);?><html> <head> <title>Bookmark app</title> </head> <body> <h1>Bookmark App</h1> <form action="<?php echo $PHP_SELF;?>" method="post"> Search <input name="strSearch" type="text" /> <input type="submit" name="submit" /> </form> <?php if(isset($_POST['submit'])){ $sql = "SELECT * FROM bookmarks WHERE url LIKE " . "'" . $_POST["strSearch"] . "'"; echo $sql; $res= mysql_query($sql); while($row = mysql_fetch_assoc($res)) { $row["url"]; } } ?> </body></html> When i type something in the search field and submit i dont get the expected result. it shouldt display the rows from the DB thats like the search string from the search field input.The DB and everything is working fine. so thats not the problem. its in the code somewhere.Whats wrong with this PHP and/or SQL ?/mads Link to comment Share on other sites More sharing options...
justsomeguy Posted March 31, 2010 Share Posted March 31, 2010 That's not going to do a wildcard search, that's only going to find records where the URL is exactly what you typed in. If you want to search for something in the URL, you need to use the wildcard character in the string.http://dev.mysql.com/doc/refman/5.0/en/str...-functions.html Link to comment Share on other sites More sharing options...
madsovenielsen Posted April 1, 2010 Author Share Posted April 1, 2010 That's not going to do a wildcard search, that's only going to find records where the URL is exactly what you typed in. If you want to search for something in the URL, you need to use the wildcard character in the string.http://dev.mysql.com/doc/refman/5.0/en/str...-functions.html Thanks. but if i search for the exact same url thats in the DB, i dont get any result ?/mads Link to comment Share on other sites More sharing options...
justsomeguy Posted April 1, 2010 Share Posted April 1, 2010 If you're sure the query is correct and the data exists, the reason why it's not finding the records is on that page I linked to. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.