473,402 Members | 2,053 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,402 software developers and data experts.

mySQL delete query

Sorry, this is simple... but i'm going cross-eyed trying to find the
error:
This code:
$delete_query = "DELETE FROM $tablename WHERE index = '$index'";
if($delete){
mysql_query($delete_query) or die(mysql_error());
}

is throwing this error:
Couldn't run query: You have an error in your SQL syntax near 'index =
15' at line 1

And everything I'm referencing says the coding is correct.
Any ideas? suggestions?

Thanks!

Jan 16 '06 #1
5 9049
php coder wrote:
Sorry, this is simple... but i'm going cross-eyed trying to find the
error:
This code:
$delete_query = "DELETE FROM $tablename WHERE index = '$index'";
if($delete){
mysql_query($delete_query) or die(mysql_error());
}

is throwing this error:
Couldn't run query: You have an error in your SQL syntax near 'index =
15' at line 1

And everything I'm referencing says the coding is correct.
Any ideas? suggestions?

Thanks!

The only thing that springs to mind is that index is a reserved word.
Have you tried echoing $delete_query and then cutting and pasting it
into a mysql command line session?

-david-

Jan 16 '06 #2
php coder wrote:
Sorry, this is simple... but i'm going cross-eyed trying to find the
error:
This code:
$delete_query = "DELETE FROM $tablename WHERE index = '$index'";
if($delete){
mysql_query($delete_query) or die(mysql_error());
}

is throwing this error:
Couldn't run query: You have an error in your SQL syntax near 'index =
15' at line 1

And everything I'm referencing says the coding is correct.
Any ideas? suggestions?

Thanks!


In addition to index being a reserved word (needs to be in back tickies,
i.e. `index`), 15 looks to be a numeric value - and therefore should NOT
be in single quotes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 16 '06 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

php coder wrote:
Couldn't run query: You have an error in your SQL syntax near 'index =
15' at line 1


Is there a column named "index" in that table?

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.5.0, and PHP
5.1.1-1 generating this signature.
Uptime: 10:18:43 up 2 days, 12:55, 1 user, load average: 0.39, 0.20, 0.12

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDy2US3jcQ2mg3Pc8RAot6AJsHBlMfC6tFdy/lrMJgUSEz3277TACeMUsn
5L8z4GRzhQPBMUDHzqYMJFI=
=MJKd
-----END PGP SIGNATURE-----
Jan 16 '06 #4
php coder wrote:
This code:
$delete_query = "DELETE FROM $tablename WHERE index = '$index'"; _____________________________________^______^

is throwing this error:
Couldn't run query: You have an error in your SQL syntax
near 'index = 15' at line 1

_______???__
What happened to te quotes?

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jan 16 '06 #5
php coder wrote:
Sorry, this is simple... but i'm going cross-eyed trying to find the
error:
This code:
$delete_query = "DELETE FROM $tablename WHERE index = '$index'";
if($delete){
mysql_query($delete_query) or die(mysql_error());
}

is throwing this error:
Couldn't run query: You have an error in your SQL syntax near 'index =
15' at line 1

And everything I'm referencing says the coding is correct.
Any ideas? suggestions?

Thanks!

I suggest:

$q = "Delete from" . $tbl_name . " where index=" . $index; //if index an
integer, or

$q = "Delete from" . $tbl_name . " where index='" . $index . "'"; //if
index a string
Jan 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bruce A. Julseth | last post by:
Newbie Question: Is there a way to import MS Access into MySQL? Maybe create a CSV or something. If so, what would be the SQL to do this? Thanks... Bruce
1
by: NotGiven | last post by:
I'd like to delete a record and all its children records at one time. How do I do that? Can you, in one SQL statement, delete from table 1 where id = 3 delete from table 2 where id = 12...
4
by: Chris | last post by:
Hi, sorry to post OT but i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two...
0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
5
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: no-email | last post by:
Hi, Below is a bunch of programs to demo the basic sql commands. Suggestions on possible improvements will be appreciated. <?php // mysql-demo.php include ("connectdb.php"); $setSQL="SET...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
9
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= | last post by:
Hi there guys, My doubt is related with MySQL and Transactions (InnoDB) so here it goes: I have a query like this: $query = 'START TRANSACTION; '; $query .= 'UPDATE sections '; $query .=...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
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
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
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.