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
?>