Search Form using PHP/mySQL and Fancybox iFrame
- by Cocoonfxmedia
I am struggling to get a search form in PHP to work with a fancybox iFrame. The search form queries a MySQL database and I want the results to show in the iFrame. However for some reason i can not get this to work. I have pasted the complete code below. Appreciate any support with this?
Java Script:
<script type="text/javascript">
$(document).ready(function() {
$("#tip5").fancybox({
'scrolling' : 'no',
'titleShow' : false,
'onClosed' : function() {
$("#login_error").hide();
}
});
});
</script>
HTML/PHP
<form method="post" action="test2.php?go" id="topF">
<input type="text" name="name">
<input type="submit" name="submit" id="tip5" href="#results" value="Search" class="buttonSubmit">
</form>
<div id="results">
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/[A-Z | a-z]+/", $_POST['name'])){
$name=$_POST['name'];
//-query the database table
$sql="SELECT id, COMPANY, TOWN, COUNTY, ServiceStandards,Active FROM main WHERE Active='Y' AND COMPANY LIKE '%" . $name . "%' OR TOWN LIKE '%" . $name . "%'AND Active='Y' OR ServiceStandards LIKE '%" . $name . "%' AND Active='Y' OR COUNTY LIKE '%" . $name . "%'AND Active='Y'";
$result5=mysql_query($sql);
$numrows=mysql_num_rows($result5);
echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>";
//-create while loop and loop through result set
while($numrow=mysql_fetch_array($result5)){
$Company =$numrow['COMPANY'];
$Town=$numrow['TOWN'];
$County=$numrow['COUNTY'];
$ID=$numrow['id'];
$Service=$numrow['ServiceStandards'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"test2.php?id=$ID\">" .$Company . "</a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
if(isset($_GET['by'])){
$letter=$_GET['by'];
$sql="SELECT *,COMPANY,COMPANY+0 FROM main WHERE Active='Y' AND COMPANY LIKE '" . $letter . "%' ORDER BY COMPANY";
$result5=mysql_query($sql);
$result6=mysql_query($sql);
$rows=mysql_num_rows($result6);
echo "<p>" .$numrows . " results found for " . $letter . "</p>";
while($rows=mysql_fetch_array($result6)){
$Company =$rows['COMPANY'];
$Town=$rows['TOWN'];
$County=$rows['COUNTY'];
$Post=$rows['POSTCODE'];
$ID=$rows['id'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . "<a href=\"test2.php?id=$ID\">" .$Company . "</a> <br/>" .$Town . ", " .$County. ", " .$Post."</li>\n";
echo "</ul>";
}
}
if(isset($_GET['id'])){
$contactid=$_GET['id'];
$sql="SELECT * FROM main WHERE Active='Y' AND id=" . $contactid;
$result7=mysql_query($sql);
while($row=mysql_fetch_array($result7)){
$Company =$row['COMPANY'];
$Town=$row['TOWN'];
$County=$row['COUNTY'];
$Email=$row['Email'];
$Web=$row['Web'];
//-display the result of the array
echo 'Company Name: '. $row['COMPANY'] . '<br />';
echo 'Town: '. $row['TOWN'] . '<br/>';
echo 'Postcode: '. $row['POSTCODE'] . '<br/>';
echo 'Telephone: '. $row['TELEPHONE'] . '<br/>';
echo 'Email: '. $row['Email'] . '<br/>';
echo 'Web: ' . "<a href=".$Web.">" .$Web . "</a> <br/>\n";
echo ' '. '<br/>';
echo 'Service: '. $row['ServiceStandards'] . '</br>';
}
}
?>
</div>