pls help me.... i want to search books from the database...but it shows some errors.

Error is Notice:

Undefined variable: searching in C:\xampp\htdocs\project\opac1.php on line 10

Code:

<html>
<body>
<form name="search" method="post" action="opac1.php">
                <div align="center"></div>
               <div align="center"></div>
              <div align="center">
                <table width="300" border="0">
                  <tr>
                    <td width="81">Author</td>
                    <td width="209">
                      <label for="textfield2"></label>
                      <input type="text" name="find" id="textfield2" />
                    </td>
                  </tr>
                  <tr>
                    <td>Title</td>
                    <td>
                      <label for="textfield3"></label>
                      <input type="text" name="find" id="textfield3" />
                    </td>
                  </tr>
                  <tr>
                    <td>Accession no</td>
                    <td>
                      <label for="textfield4"></label>
                      <input type="number" name="find" id="textfield4" />
                    </td>
                  </tr>
                  <tr>
                    <td>Edition</td>
                    <td>
                      <label for="textfield5"></label>
                      <input type="number" name="find" id="textfield5" />
                    </td>
                  </tr>
                  <tr>
                    <td>Publisher</td>
                    <td>
                      <label for="textfield6"></label>
                      <input type="text" name="find" id="textfield6" />
                    </td>
                  </tr>
                </table>
                <table width="300" border="0">
                  <tr>
                    <td width="81">Year</td>
                    <td width="209">
                      <label for="textfield7"></label>
                      <input type="number" name="find" id="textfield7" />
                    </td>
                  </tr>
                </table>
<p>Â </p>
               <input type="hidden" name="searching" value="yes" />
                           <input type="submit" name="search" value="Search" />
                  <input type="submit" name="button2" value="Clear" />
                  <img src="images/images (9).jpg" width="104" height="104" longdesc="images/images (9).jpg" />
                </form>
</body>
</html>

php page is:

<?php
  if ($searching =="yes"){
  echo "<h3>Search Results</h3><p>";
  if ($find == ""){
  echo "<p>Please Enter a search term";
  exit;
  }

 // Otherwise we connect to our Database 
 $con = mysql_connect("localhost");
if (!$con)
  {
  mysql_select_db("test") or die('Could not connect: ' . 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 
 $data = mysql_query("SELECT * FROM book WHERE upper($field) LIKE'%$find%'"); 

 //And we display the results 
 while($result = mysql_fetch_array( $data )) 
 { 
 echo $result['book id']; 
 echo " "; 
 echo $result['access no']; 
 echo "<br>"; 
 echo $result['author']; 
 echo "<br>"; 
 echo $result['title']; 
 echo " "; 
 echo $result['publisher']; 
 echo "<br>"; 
 echo $result['year']; 
 echo "<br>"; 
 echo "<br>"; 
 } 

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 
 } 
 ?>

Recommended Answers

All 3 Replies

The answer is in the message. You are using $searching without first give a value to it …

I gave the value through my html page….can u explain...because I’m totally confused

you are not passing the value to your searching page, u are not reading it in the top of ur search php page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.