Solved

help with sql query setting

Posted on 2007-11-21
11
166 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
  • 6
  • 3
  • 2
11 Comments
 
LVL 4

Expert Comment

by:simonkin
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
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
Comment Utility
i use mysql...u know what...i see that the tel1 is text type...how can it effect this?
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
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
Comment Utility
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
Comment Utility
REALY, HOW IF I STORE NUMBERS INSIDE MYSQL COLUMN THAT DEFINED AS TEXT...HOW BAD CAN OT BE?:)
0
 

Author Comment

by:sasha85
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

6 Experts available now in Live!

Get 1:1 Help Now