0

hi im working on a search field in drupal for a system that maintains student information.
i have one interface that has the search student info box and the other which is search results
i wrote some php code to search the and there are no errors yet still its not working. when i press find it simply redirects it to front page of drupal.
without any results being showed.
i will show the code below, please tell me what to do..

<strong>SEARCH</strong><br/>
<form style="background-color:#F2F2F2; padding:10px; border:1px solid; border-color:#084B8A; width:650px;">
<table>
<tr>
<td>Name:</td><td width="300"><input type="text" size="60" name="searchname"/></td>
</tr>
<tr>
<td>Course:</td>
<td>
<select>
<option>ALL</option>
<option>CTHE</option>
</select>
</td>
</tr>
<tr>
<td>Date of Course:</td>
<td>
<select>
<option>2009</option>
<option>2010</option>
</select> 
<select>
<option>Jan</option>
<option>Feb</option>
</select>
</td>
</tr>
<tr>
<td>Completed Successfully:</td>
<td width="500">
<input type="radio" name="cs">YES</radio>  <input type="radio" name="cs">NO</radio>  <input type="radio" name="cs" checked>ALL</radio>
</td>
</tr>
<tr>
<td>Payments Made:</td>
<td width="500">
<input type="radio" name="pm">YES</radio>  <input type="radio" name="pm">NO</radio>  <input type="radio" name="pm" checked>ALL</radio>
</td>
</tr>
</table>
<input type="submit" value="FIND" style="float:right;" class="up" onmouseover="this.className='over'" onmouseout="this.className='up'"/> 
</form>
</html>

<?php
$searchname=$_GET["searchname"]; //Get the search text
$con = mysql_connect('localhost', 'root', ''); //connect to the database
    if (!$con) //if cannot connect to the database, ternimate the process
        {
        die('Could not connect: ' . mysql_error());
        }

    mysql_select_db("sdc_cpds", $con); //Select the databse
    $sql="SELECT * FROM course_participant WHERE name='".$searchname."'"; //Select Query
    $result = mysql_query($sql); //execute the query and get the result
    if($result==1)  //If there is a result, display it
    {
                echo $row['searchname'] ;
    }
    else // If no result found
    {
        echo "No result found!"; //Display the "not found" mesasge
    }
mysql_close($con); //Close the database connection

?>

Edited by Reverend Jim: Fixed formatting

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rukshilag
0

Try to do the following way:

$sql="SELECT * FROM course_participant WHERE name like '%".$searchname."%'"; //Select Query
$result = mysql_query($sql); //execute the query and get the result
if(mysql_num_rows($result) > 0) //If there is a result, display it
{
	echo "The search results are:<br />";
	while ($row = mysql_fetch_assoc($result)) {
		echo $row['name']."<br />";
	}
}
else // If no result found
{
echo "No result found!"; //Display the "not found" mesasge
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.