Solved

SQL Issue

Posted on 2014-03-03
3
235 Views
Last Modified: 2014-03-03
What is wrong with this query?

SELECT * from subcat_docs where prim = 'Polywrap' and category = '20' Perforations' and subcategory = 'Black 200/400''

When I run this phpMyadmin, it says error in the syntax near "where catag".

The attached shows the table structure.

Thanks
subcat-docs-str.jpg
0
Comment
Question by:Richard Korts
3 Comments
 
LVL 18

Accepted Solution

by:
Matthew Kelly earned 250 total points
ID: 39902009
Can you post the exact phpMyAdmin message?

I just made that table, and ran that query (copy and pasted) the below, and it ran without error.

SELECT * from subcat_docs where prim = 'Polywrap' and category = '20' Perforations' and subcategory = 'Black 200/400''

Open in new window

0
 

Author Comment

by:Richard Korts
ID: 39902105
That's crazy; I just ran it again, no error.

Can you tell we how to escape the data (from a MySQL point of view)  if there are ' in the data itself?

Thanks
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 250 total points
ID: 39902108
Just add a backslash before it eg
where word = 'can\'t'

Open in new window

You can often avoid escaping by using double quotes too.

When you're writing code to perform queries with user supplied data, you need to have foolproof methods to ensure any special characters get properly escaped, or your software can become vulnerable to SQL injection attack. Let me know if you want more information on this (it's language dependent).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best database setup for image uploads 6 50
Have issues with Query MySQL 9 54
Mysql sync between 3-4 mysql db 4 23
MySQL  on Tomcat 8 22
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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

19 Experts available now in Live!

Get 1:1 Help Now