<html>
<head>
<basefont face="Arial">
</head>
<body>
<?php
error_reporting(E_ALL);
if (!isset($_POST['Submit'])) {
// form not submitted
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
search
<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>
</select>
<input type="Submit" value="Submit" name="Submit">
</form>
<?php
}
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());
$num=mysql_numrows($result);
mysql_close($connect);
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$company=mysql_result($result,$i,"arCompanyname");
$address=mysql_result($result,$i,"arAddress");
echo "<br>Company: $company<br><br>Address: $address<hr><br>";
$i++;
}
}
?>
</body>
</html>
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: