<basefont face="Arial">

if (!isset($_POST['Submit'])) {
// form not submitted

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  <input type="text" name="search">
   <select size="1" name="dropdown">
    <option value="" selected>search By...</option>
    <option value="first">Company</option>
    <option value="last">Address</option>  
  <input type="Submit" value="Submit" name="Submit"> 


else {

// Server Variables
$host = "localhost";
$user = "mdti";
$pass = "tnet";
$db = "ojt";

$search = empty($_POST['search'])? die ("ERROR: Enter search Criteria") : mysql_escape_string($_POST['search']);
$dropdown = empty($_POST['dropdown'])? die ("ERROR: Select from dropdown") : mysql_escape_string($_POST['dropdown']);

// Open Connection

$connect = mysql_connect($host, $user, $pass) or die ("Unable to connect to host");

//Select Database

mysql_select_db($db) or die ("Unable to connect to database");

//Create query

$query = "SELECT arCompanyname, arAddress FROM ar WHERE $dropdown like'$search'" or die (mysql_error());

$result = mysql_query($query) or die (mysql_error());



echo "<b><center>Database Output</center></b><br><br>";

while ($i < $num) {


echo "<br>Company: $company<br><br>Address: $address<hr><br>";



Good day! I'm just a newbie in php programming so I need somebody to help me with this one. I still cannot find what's wrong with this code. I created a search form with drop down menu to filter the results. But nothing happens when I do a searching. It's either it's just refreshes the page or display error criteria message. any answer will be appreciated! :) thanks in advance! Here is the code:

Hi, there are few errors here:

$query = "SELECT arCompanyname, arAddress FROM ar WHERE $dropdown like'$search'" or die (mysql_error());

$result = mysql_query($query) or die (mysql_error());

$query is a string, so do not include or die(mysql_error()) otherwise the mysql_query() will return FALSE. Then, mysql_numrows() does not exists, the correct function is mysql_num_rows(). If you still get errors then paste them here.

Last, but not least: since you're still learning, I strongy suggest you to avoid the MySQL API: it is deprecated and will be removed from PHP; learn MySQLi or PDO, for more information read this link:

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.