473,756 Members | 5,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($de lete_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 9069
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($de lete_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($de lete_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*******@attgl obal.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)

iD8DBQFDy2US3jc Q2mg3Pc8RAot6AJ sHBlMfC6tFdy/lrMJgUSEz3277TA CeMUsn
5L8z4GRzhQPBMUD HzqYMJFI=
=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($de lete_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
15194
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
37024
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 delete from table 3 where id = 12 ......
4
5307
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 tables. The tables i have are: questionnaires (id, name); questionnaire_questions (questionnaires_id, id, name, qf_type)
0
6460
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 results below, I would think that the delete should have deleted row 1 {1 5 me) and not row 3 (1 5 they) when I run this statement delete t1 from t, t1 where t.id = t1.id and t.id=1 and t.name = 'me'; Any ideas on why row 2 is deleted?
5
4011
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 fieldX=valueX WHERE id IN (SELECT tX.id FROM tableX AS tX WHERE tX.fieldY=valueY AND filedZ=valueZ);
0
3947
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
1
1920
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 FOREIGN_KEY_CHECKS=0"; $dropSQL="DROP TABLE IF EXISTS temp";
9
2797
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 this: id Name Surname pictr0 picrt1 pictr2 pictr3
9
4805
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 .= 'SET position=position-%d ';
6
38518
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 through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
0
10028
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9868
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9836
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9707
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5139
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2664
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.