473,395 Members | 1,692 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.

Mysql error

65
Hi friends,

I don't know whether this thread is related to this forum or php forum.
Please forgive me, if i had done this mistake.

Can anyone tell me is it possible to write a query attached with php variable in where clause?

for example,

Expand|Select|Wrap|Line Numbers
  1. $nm=implode(",",$si[name]);
  2. $result=get_records_sql("select name, id from a where name in ($nm)");
  3. echo $result;
But this query shows me the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'something' at line 1.

can anybody tell me what is it and what i have to do to fix this?
Please help me out.

Thanx n Regards
Yas...
Apr 11 '08 #1
4 1167
debasisdas
8,127 Expert 4TB
You need to concatinate the variable with sql ,can't include that directly .

Again the variable in the first line might return multiple values. That might be an array .
Apr 11 '08 #2
mwasif
802 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. $nm=implode(",",$si[name]);
  2. $result=get_records_sql("select name, id from a where name in ($nm)");
  3. echo $result;
If $si[name] is string then you must have to use ',' as a separater for IN () and make sure you have some value in $nm.

Try the below code
Expand|Select|Wrap|Line Numbers
  1. $nm=implode("','",$si["name"]);
  2. $result=get_records_sql("select name, id from a where name in ('$nm')");
  3. echo $result;
If you still face any problem then use mysql_error() to get the exact error message and post here.
Apr 12 '08 #3
yasmine
65
If $si[name] is string then you must have to use ',' as a separater for IN () and make sure you have some value in $nm.

Try the below code
Expand|Select|Wrap|Line Numbers
  1. $nm=implode("','",$si["name"]);
  2. $result=get_records_sql("select name, id from a where name in ('$nm')");
  3. echo $result;
If you still face any problem then use mysql_error() to get the exact error message and post here.

Thanks a lot mwasif.
I didn't use single quotes for separation. Now its working well.


Thank u very much....

Regards
Yas....
Apr 14 '08 #4
mwasif
802 Expert 512MB
You are welcome.
Apr 14 '08 #5

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

Similar topics

2
by: Cathy Hui | last post by:
Do u know why do i get the following message when trying to build the MySql-Python (1.2.0) on my Solaris 8 system? (with mysql 4.0.21 and python 2.4). thanks! error mesg: ld: fatal:...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
0
by: Dennis Francis B. Tutanes | last post by:
$B$*@$OC$K$J$C$F$*$j$^$9!#(B $B%D%?%M%9(B@TSTI$B$G$9!#(B SEND-PR: -*- send-pr -*- SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as SEND-PR: will all comments (text...
4
by: Adam Smith | last post by:
I have a dedicated server running 'FreeBSD 4.9 STABLE' at a hosting site. They have done some default installations, presumably from the CVS ports package ??. Herein lies the problem, "I do not...
3
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
1
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
8
by: sundeep.kumara | last post by:
hi all, I am a newbie .....I have compiled the source code of mysql-4.1.9 on PPC-Linux Its not giving any errors during configure,make or make install. But,when i try to start the server...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
1
by: Steve Ametjan | last post by:
I've been trying to get MySQL-python to install on Leopard for the past couple of days, and I keep running into relatively the same error. I'm hoping that someone on this list will be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.