GetDotted Domains

Viewing Thread:
"A 'lil MySQL help required please..."

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Tue 04/07/06 at 21:47
Regular
"Peace Respect Punk"
Posts: 8,069
So I'm using PHP to generate some queries for MySQL, then executing them. They didn't seem to be working, so I started echoing the query strings, then mysql_error() after the query had been executed, and I get the following output:


UPDATE userbasket SET size = 'N', quantity = '1' WHERE index = '1'

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 'index = '1'' at line 1


Now the table name is definitely right, I've used it in a select query, and there's definitely a field named 'index' in the table... I'm aware there's no semi-colon at the end of the query, but I've tried adding one and the error is the same... I just can't see what's wrong with it. I thought maybe I didn't need the index number (1 in this case) in ''s, but again, removing them made no difference to the error. The index field in the database is an auto-increment integer, if that makes any difference.

Thanks for any help!
Fri 07/07/06 at 18:24
Regular
"Peace Respect Punk"
Posts: 8,069
Ah, ok.

Well, I'll just try to avoid using "index" as a field name in future... Seems more trouble than it's worth!
Thu 06/07/06 at 18:48
Regular
"Devil in disguise"
Posts: 3,151
Oops, sorry, my fault.
Just noticed I put the wrong quotes. 'index' would just treat it as text (hence why your update didnt work), you need `index` to have it treated it as a field
Thu 06/07/06 at 15:56
Regular
"Peace Respect Punk"
Posts: 8,069
Okay, now it appears index is being recognised as the field name, as I'm no loger getting any errors. However, the database is still not being updated. Whenever I echo mysql_affected_rows after an update or delete I always get 0.

I'm definitely using index numbers that exist as I'm getting them from this table in the first place... So it can't be the 'WHERE' clause I don't think.

I know it should return 0 if the details of the UPDATE query are the same as they were before the update, but the details are not the same, as I've echoed the query string and seen they are different from details currently in the database.

I just can't see anything wrong with the query strings, so have no idea why the queries wouldn't be working... They are as before, except the index is in single quotes as suggested...


[EDIT] - Think I may have fixed it. Changed the index field to ID, then changed all the mentions of index in the SQL queries and it all seems to work now!
Wed 05/07/06 at 02:53
Regular
"Peace Respect Punk"
Posts: 8,069
Ahhhhh.

Thanks, very helpful, as always!
Tue 04/07/06 at 22:40
Regular
"Devil in disguise"
Posts: 3,151
Index is a reserved word in mysql, I'd guess thats why its complaining. Either rename your field or put it in quotes eg 'index'=1
Tue 04/07/06 at 21:47
Regular
"Peace Respect Punk"
Posts: 8,069
So I'm using PHP to generate some queries for MySQL, then executing them. They didn't seem to be working, so I started echoing the query strings, then mysql_error() after the query had been executed, and I get the following output:


UPDATE userbasket SET size = 'N', quantity = '1' WHERE index = '1'

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 'index = '1'' at line 1


Now the table name is definitely right, I've used it in a select query, and there's definitely a field named 'index' in the table... I'm aware there's no semi-colon at the end of the query, but I've tried adding one and the error is the same... I just can't see what's wrong with it. I thought maybe I didn't need the index number (1 in this case) in ''s, but again, removing them made no difference to the error. The index field in the database is an auto-increment integer, if that makes any difference.

Thanks for any help!

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Unrivalled services
Freeola has to be one of, if not the best, ISP around as the services they offer seem unrivalled.
Just a quick note to say thanks for a very good service ... in fact excellent service..
I am very happy with your customer service and speed and quality of my broadband connection .. keep up the good work . and a good new year to all of you at freeola.
Matthew Bradley

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.