470,821 Members | 2,054 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

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 8865
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Bruce A. Julseth | last post: by
1 post views Thread by NotGiven | last post: by
4 posts views Thread by Chris | last post: by
reply views Thread by Gordon | last post: by
reply views Thread by Mike Chirico | last post: by
1 post views Thread by no-email | last post: by
9 posts views Thread by Dejan | last post: by
9 posts views Thread by =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= | last post: by
Atli
6 posts views Thread by Atli | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.