473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to use input data from a form with multiple values in a sql search?

Hey,

Is it possible to use the value of an input such as <input name=city type=hidden value=usa> to include in a sql select? For instance i would be wanting to
SELECT * from cities where city=the input value above. Can i make it into a variable or something to make it usable in an sql select?

Otherwise i have currently passed it to the header which works fine like this www.example.com/cities.php?city=usa .
And i have used $_GET to get the value of city.
SELECT * from cities where city LIKE '%".$city."%' . But when their is more than 1 city it doesnt work.
www.example.com/cities.php?city=usa canada
SELECT * from cities where city LIKE '%".$city."%' .
Can i split the usa and canada to be like
SELECT * from cities where city LIKE 'usa' OR city LIKE 'canada' .

Any suggestions would be great. I can easily use the input but im not sure if i can get the value out if to use in sql. otherwise can i $_GET the .php?city=usa canada to become
$city1= usa
$city2= canada
instead of $city=usa canada

thanks.
Feb 1 '11 #1

✓ answered by Niheel

You should split it.

if cities.php?city=usa canada

$city = explode(" ", $city);

$city[0] // is the value for the first city
$city[1] // is the value for the second city

Also make sure to clean and secure your input, because you're giving it direct access to your database.

3 1924
Niheel
2,460 Expert Mod 2GB
You should split it.

if cities.php?city=usa canada

$city = explode(" ", $city);

$city[0] // is the value for the first city
$city[1] // is the value for the second city

Also make sure to clean and secure your input, because you're giving it direct access to your database.
Feb 1 '11 #2
Thanks Again for your help Niheel. I am only new to php and uni hasnt really touched on security yet. I have cleaned and secured it as it submits into the database on the insert page, but are you saying i have to do some security on the .php$city=usa candada page itself? If i stopped users from changing the value of $city would that be sufficient?

Thanks matt.
Feb 1 '11 #3
Markus
6,050 Expert 4TB
No. You have no control over what is sent to your server. You do, however, have control over how you process that information. Niheel was suggesting you look into SQL injection. You'll find lots of information on Google on how to prevent this in PHP.
Feb 2 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: RC | last post by:
I am try test a simple HTML form with PHP <form method=POST action="testing.php"> Cat <input type="checkbox" name="pet" value="cat"> Dog <input type="checkbox" name="pet" value="dog"> Pig...
2
by: Jen F. | last post by:
I have inherited a medical database in which there are multiple values stored in a single field (ie. "Current Conditions" field might contain 1-20 different conditions, separated by comma (ie....
17
by: stathis gotsis | last post by:
Hello everyone, I am tying to come up with an elegant way to process some input data that come from a form. When the user hits the 'Submit' button, i want the form to appear again with the...
10
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
23
blyxx86
by: blyxx86 | last post by:
I am trying to filter multiple entries with only one search box. That way the user can type whatever they want and find all the values that contain what they enter. Private Sub...
3
by: mukeshsrivastav | last post by:
dear sir i want to move form excel to access. i have 5 excel file having same formats and fields.now i want to import all data in one access table. importing one file is easy .but importing and...
4
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You...
3
by: gyap88 | last post by:
My search engine in visual basic 2005 has 4 textbox for users to input values, named textbox1,textbox2,textbox3,textbox4. I have a string assigned to each of the textbox named...
0
by: waterfall | last post by:
Hi, Im developing a C# web application in VS2005. Ive 2 textboxes for user input and a button. First textbox gets string as input(e.g, ItemA, ItemB etc.) Second textbox get int as input(1,2,3,4...
2
by: rka77 | last post by:
Hi, I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file - Set : 1 Date:...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.