Solved

Multiple Criteria Search

Posted on 2013-05-23
3
257 Views
Last Modified: 2013-05-23
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
Comment
Question by:DS928
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Mark Brady earned 500 total points
ID: 39192615
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
 

Author Closing Comment

by:DS928
ID: 39192694
Thank you very much!  I was sweating bullets there for a moment!
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 39193210
You're welcome
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now