Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

help with sql query setting

Posted on 2007-11-21
11
Medium Priority
?
173 Views
Last Modified: 2010-03-20
pphon = request.form("phon")
mySQL = "SELECT * FROM crminfo WHERE tel1 LIKE %" &pphon& "%"

i need to find inside column tel1 number like the nuber that was recieved from the submited form.
some how that wuery do not work fine...
what, what shell i do? where i got wrong?;)
0
Comment
Question by:sasha85
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Expert Comment

by:simonkin
ID: 20330146
Hi,

Try this, your syntax is wrong...

Example:


pphon = request.form("phon")
mySQL = "SELECT * FROM crminfo WHERE tel1 LIKE'%&pphon&%'"

Open in new window

0
 
LVL 4

Expert Comment

by:simonkin
ID: 20330152
Ooops...

Remove the ampersands '&' too...


$pphon = request.form("phon")
mySQL = "SELECT * FROM crminfo WHERE tel1 LIKE'%$pphon%'"

Open in new window

0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20330179
sasha85,

The ampersands are needed to use the variable.  They should be fine as you have it.

What type of field is tel1?  Even though you use a number if it is a string or text field then you need single quotes or sometype of delimiter.  What type of field is it and what database do you use?  I assume MySQL but please confirm.

Try ...

mySQL = "SELECT * FROM crminfo WHERE tel1 LIKE '%" &pphon& "%'"

Let me know if you have any questions or need more information.

b0lsc0tt
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20330192
sasha85,

Also, try running the query outside of your code (i.e. in MySQL or using a 'query analyser') to see if there are no results for that query.  The problem may not be a problem but just no results.

Let me know if you have a question.

b0lsc0tt
0
 

Author Comment

by:sasha85
ID: 20330252
i use mysql...u know what...i see that the tel1 is text type...how can it effect this?
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20330279
If it is that type then it has to have the delimiters.  Look at the code in my last post and that should fix it.  For MySQL the delimiters for text/strings are single quotes (').  When used with LIKE the % sign would go inside the single quotes with the rest of the "string."

Let me know how it works or if you have a question.  Thanks for confirming the type of DB and field.

bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20330289
Sorry, not really "last" post.  See http:#20330179.

The code is ...

mySQL = "SELECT * FROM crminfo WHERE tel1 LIKE '%" &pphon& "%'"

bol
0
 

Author Comment

by:sasha85
ID: 20330354
REALY, HOW IF I STORE NUMBERS INSIDE MYSQL COLUMN THAT DEFINED AS TEXT...HOW BAD CAN OT BE?:)
0
 

Author Comment

by:sasha85
ID: 20330429
i defined it text cause i wanted prevent situation where user will disable javascript validations and will insert chars instead numbers...what would give him an error...
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 2000 total points
ID: 20330508
Please don't use all caps unless you are really yelling at me. :)  (I hope you aren't)

What is the info in that field?  How will it be used?  It seems like the info is phone number so text/string is appropriate.  If you tried to use a number type then entering 800-555-1212 would just leave -967 in that field (the math would be done).  In most cases phone numbers, zips, etc are text fields for this reason.

However if it is a number then it can be a disadvantage to use a text field type.  A detailed explanation on that can be done in a different question (one of its own) but the examples above should give you an idea.

Let me know if the suggestion above worked or not or if you have a question.

bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20332151
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

730 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