Hi there! I have an SQL database and a website both hosted by Godaddy. I’m using Wordpress as a CMS. I need to code a search bar to query my database. I’ve started coding a bit of a search bar and have it showing up, but not querying the database… I’d very much like to be able to search in the box and it query my database and display the table. The tables are:
Reference
FIRSTNAME
LASTNAME
ADDRESS
ADDRESS2LINE
CITY
STATE
ZIP4
ZIP
LOANAMT1
MORT1LOANDATE
MORT1LOANTYPE
LENDER1
The database name is i2369553_wp2
the table name is New Data
And here is the code ive written.
Search
Seach for: in Reference First Name Last Name Address Address2 City State Zip Loan Amount Mortgage Loan Date Loan Type/option> Lender <?php //This is only displayed if they have submitted the form if ($searching == "yes") { echo "Results
"; //If they did not enter a search term we give them an error if ($find == "") { echo "
You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "databasename", "mypassword") or die(mysql_error()); mysql_select_db("New Data") or die(mysql_error()); //filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //to search for search terms, in the field the user specified $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); //displays the results while($result = mysql_fetch_array( $data )) { echo $result['Reference']; echo " "; echo $result['FIRSTNAME']; echo " "; echo $result['LASTNAME']; echo " "; echo $result['ADDRESS']; echo " "; } //This counts the number or results - and if there weren'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 "; } //reminds them what they searched for echo "Searched For: " .$find; } ?>
Thanks!!