Ad:
 
  • PHP Discussion Thread
  • Unsolved
  • Views: 1375
  • PHP RSS
Similar Threads
Mar 13th, 2010
0

PHP coding for a Search Field on Drupal

Expand Post »
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

?>
Reputation Points: 10
Solved Threads: 0
Junior Poster
rukshilag is offline Offline
101 posts
since Oct 2009
Mar 14th, 2010
0

Re: PHP coding for a Search Field on Drupal

Try to do the following way:
PHP Syntax (Toggle Plain Text)
  1. $sql="SELECT * FROM course_participant WHERE name like '%".$searchname."%'"; //Select Query
  2. $result = mysql_query($sql); //execute the query and get the result
  3. if(mysql_num_rows($result) > 0) //If there is a result, display it
  4. {
  5. echo "The search results are:<br />";
  6. while ($row = mysql_fetch_assoc($result)) {
  7. echo $row['name']."<br />";
  8. }
  9. }
  10. else // If no result found
  11. {
  12. echo "No result found!"; //Display the "not found" mesasge
  13. }
Reputation Points: 16
Solved Threads: 17
Junior Poster in Training
as.bhanuprakash is offline Offline
87 posts
since Dec 2009
Mar 14th, 2010
0

is the html form right?

http://localhost/sdc/?q=node/2 - that is wht i put as the form action.. php code seems ok...
Reputation Points: 10
Solved Threads: 0
Junior Poster
rukshilag is offline Offline
101 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Parse Error?
Next Thread in PHP Forum Timeline: How do I find out the number of parameters passed into function?





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC