Jump to content

Recommended Posts

Hello there

 

I'm having a bit of trouble getting my search function to work.

 

this is my search script: http://michael-nguyen.com/greeneco/search.php

 

<form action="<?=$PHP_SELF?>" method="post" name="search" class="style1">
  <div align="center">Seach for: 
    <input type="text" name="find" /> 
    in
    <Select NAME="field">
      <Option VALUE="id">ID</option>
      <Option VALUE="name">Name</option>
      <Option VALUE="pledge">Pledge</option>
  <Option VALUE="points">Points</option>
      <Option VALUE="costs">Costs</option>
      <Option VALUE="kwh">Kwh</option>
      <Option VALUE="carbon">Carbon</option>
      <Option VALUE="classification">Classificationn</option>
      <Option VALUE="energysaving">Energy Saving</option>
      <Option VALUE="enabled">Enabled</option>
    </Select>
    <input type="hidden" name="searching" value="yes" />
    <input type="submit" name="search" value="Search" />
  </div>
</form>

<span class="style1">
<table border="1" width="100%">
</span>
<tr><strong>

  <td width="35" class="style1"><span class="style5">ID</span></td>
  <td width="78" class="style1"><span class="style5">Name</span></td>
      <td width="78" class="style1"><span class="style5">Pledge</span></td>
      <td width="132" class="style1"><span class="style5">Points</span></td>
      <td width="194" class="style1"><span class="style5">Cost</span></td>
  <td width="78" class="style1"><span class="style5">Kwh</span></td>
  <td width="78" class="style1"><span class="style5">Carbon</span></td>
      <td width="72" class="style1"><span class="style5">Classification</span></td>
      <td width="150" class="style1"><span class="style5">Energy Saving</span></td>
      <td width="91" class="style1"><span class="style5">Enabled</span></td></strong>
</tr>


<p class="style1">

<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>Please enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect('localhost','admin','pass') or die(mysql_error());
mysql_select_db("table") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$results = mysql_query("SELECT * FROM table WHERE upper($field) LIKE'%$find%'");

//And we display the results
while ($a = mysql_fetch_array($results)) {

          echo'<TR>
              <TD>'.$a['id'].'</TD>
		  <TD>'.$a['name'].'</TD>
              <TD>'.$a['pledge'].'</TD>
              <TD>'.$a['points'].'</TD>
              <TD>'.$a['cost'].'</TD>
		  <TD>'.$a['kwh'].'</TD>
		  <TD>'.$a['carbon'].'</TD>
              <TD>'.$a['classification'].'</TD>
              <TD>'.$a['energysaving'].'</TD>
              <TD>'.$a['enabled'].'</TD>
              </TR>';
       };

       print("</TABLE>");

       } else {

       print("No results to display");

       };


//This counts the number or results - and if there wasn't any it gives them a little message explaining that

{
echo "";
}


?>

 

I'm very sure I have the database connection correct but it just doesn't seem to display any results.

Thank you for your replies in advance.

 

Michael

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.