• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

Multiple Criteria Search

I have a table that includes Street, City, State.  If I have a searchbox on a website thats asks for Street, City, State in this format seperated by commas, how do I extract the three values to search the table?
0
DS928
Asked:
DS928
  • 2
1 Solution
 
Mark BradyCommented:
Very easy to do with php. Assuming your form will post that csv (comma separated values) to the script you would do this. I am assuming you already have a database connection open before running my code (else the mysql_real_escape_string() part won't work)

<?php

$address = isset($_POST['address']) ? $_POST['address'] : null;

if (!is_null($address)) {
     // we need to explode them into separate values
     $address = array_map('trim', explode(',' $address));

    // now because you know the order of them you can pick them out like this

    $street = mysql_real_escape_string($address[0]);
    $city = mysql_real_escape_string($address[1]);
    $state = mysql_real_escape_string($address[2]);

// now you can insert them into your database safely

}

?>

Open in new window

0
 
DS928Author Commented:
Thank you very much!  I was sweating bullets there for a moment!
0
 
Mark BradyCommented:
You're welcome
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now