How to Search result

I am designing a Plugin that search through mysql database and display the result.

this is the code for my "content.php"



<div style="text-align:center">

<form action="mod/openProgram_widget/search.php" method="post">

     Search: <input type="text" name="term" /><br />

    <input type="submit" name="submit" value="Submit" />






And it points to "search.php" which is made of the following.



 mysql_connect ("localhost", "root","")  or die (mysql_error());

 mysql_select_db ("study");


 $term = $_POST['term'];


$sql = mysql_query("select * from testtable where FName like '%$term%'");

while ($row = mysql_fetch_array($sql)){

    echo 'ID: '.$row['ID'];

    echo '<br/> Name  of School: '.$row['Name of School'];

    echo '<br/> Study Name: '.$row['Study Name'];

    echo '<br/> Description: '.$row['Description'];

echo '<br/> Contact: '.$row['Contact'];

    echo '<br/><br/>';



But when i click search, it opens an empty new browser window, and not the search results. 

Please i need help ?

  • This is not the proper way of doing Elgg coding

    • To create the search for put the html for search input inside views/yourplugin/forms/search.php
    • Create a corresponding action file
    Also you are directly making the query with our doing any filtering on input. This is a big security issue. Have alook at any of the bundled plugin and see how the form and actions are created in elgg
    If you can explain your requirements, community can help you with proper API
  • Thank you for the quick response. 


    Please, i am newbie to elgg, but i am prepared to become a Pro. I am designing a An Education and Training Program for Information Service Plugin for my University,We will manually Populate its database, When users add the plugin, they can search through and display a result;

    The Database has the following:

    Programme ID(key)

    Programme Name:

    Programme Type:


    Start Date:

    End Date:

    Contact Person:


    A Search that will "query" it, and display the result; 

    I hope members understand my situation now and i ll be glad to get the needed inputs.


  • You can achieve this without creating any new tables for this. Just creat it as an Elgg entity, and assign the values as metadatas. See the documentation at and read the DB structure and elgg data model. Have a look at

    To fetch the data you can then use the elgg_get_entities_from_metadata() function

    If you are ready to spend a few bucks and willing to read and learn about Elgg, get the book on Elgg from

  • generally - the comments about the 'Elgg way' is mostly on the mark ;) 
    If you want to spend tome to learn how Elgg is designed, the API functioning and all those other nice things about Elgg -- be ready for some initial hard work. you'll get there.. That WIki link above is a good place to start. Like anything else - it will appear too difficult at first.. but more effort = less pain..;;P;X
    re: your PHP code that displays that 'empty window' -->
    try this ==>
    $sql=mysql_query(" select * from testtable where FName like '%$term%' ");
    echo"<h2>TERM=($term)</h2><h2>SQL=($sql)</h2>";//:DC: dbg
    exit();//:DC: dbg
    . . .
    you'll see what if wrong with your code soon ;-oO

  • Thank you, i just bought the book from amazon and i am still reading, but i need to finish this, i am behind shedule.

    @DhrupDeScoop , I followed your reply ,thank you,i am now getting this error :



    the name KNUST is the search query i entered, to search in the database. But it still opens a new browser tab.

  • Please, find the url, for my plugin beloww

    I would be glad,if i can get something similar, so that i can make modifications and develop it quickly. To let members know how serious i am to learn elgg and help me out, i am at chapter four(Sharing Content) of the book i bought 45 minutes ago,

  • $term = $_POST['term'];
    $sqlX = " select * from testtable where FName like '%$term%' ";
    echo"<h2>TERM=($term)</h2><h2>SQL=($sqlX)</h2>";//:DC: dbg
    $sql = mysql_query($sqlX);
    . . .

  • @ DhrupDeScoop, now i am  getting server error. Can you please add some notes ?