dream25 Posted June 5, 2007 Share Posted June 5, 2007 Hi.. i have one more doubt.. please clear it.. i wrote a code for search engine.. if i run that code.. its shows.. nothing.. the code has follows.. <html> <body> Search: <form method='post' action='search.php'> <input type='text' name='search' size='25' maxlength='25'> <input type='Submit' name=' Search ' value='Submit'> </form> </body> </html> <?php $host="localhost"; $username="root"; $password=""; $db_name="database1"; $tbl_name="table1"; if(isset($_POST['submit'])) { echo "Your Name Is " . $_POST['search'] ; mysql_connect("$localhost", "$username", "$password")or die("Cannot connect"); mysql_select_db("$db_name")or die("Cannot select database"); $search=$_POST["search"]; $result = mysql_query("SELECT * FROM '$tbl_name' WHERE name LIKE '%$search%'"); while($r=@mysql_fetch_array($result)) { //change the names to your columns $topic=$r["topic"]; $message=$r["message"]; $name=$r["name"]; $date=$r["date"]; $id=$r["id"]; //display the row echo "$id | $topic by $name at $date $message"; } if(!search){ echo "Please enter a search."; } else { echo "Sorry, there were no searches with the criteria of $search."; } } ?> Thanks In Advance Link to comment https://forums.phpfreaks.com/topic/54246-search-engine-prob/ Share on other sites More sharing options...
Lumio Posted June 5, 2007 Share Posted June 5, 2007 Please use code-tags! The solution: Your sql-query has an error. You see nothing because you ignore the error with the @ The error is here: FROM '$tbl_name'. You only need those single quotes for values. For tables and coumns use a gravis: ` $result = mysql_query("SELECT * FROM `$tbl_name` WHERE name LIKE '%$search%'"); also your code can be hacked very easy Link to comment https://forums.phpfreaks.com/topic/54246-search-engine-prob/#findComment-268223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.