Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with update record (PHP/My SQL)

Explorer ,
Mar 16, 2009 Mar 16, 2009
Can anyone help me figure this one out.
I have a form which contains two text areas 'start-date' and 'finish-date'. Ideally when filled in with a date (eg 2009-03-16 they will update the relevant records in the database (MySQL 'date' fields).

This is the code I have a the moment

******************************************************************************************
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "frm_editdate")) {
$updateSQL = sprintf("UPDATE dates08 SET start-date=%s, finish-date=%s WHERE id=%s",
GetSQLValueString($_POST['start-date'], "date"),
GetSQLValueString($_POST['finish-date'], "date"),
GetSQLValueString($_POST['id'], "int"));

******************************************************************************************

But when I submit the form I get this message:

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 '-date='2009-01-30' WHERE id=2679' at line 1

I've tried everything I can think of but I can't get it to work.
TOPICS
Server side applications
522
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 16, 2009 Mar 16, 2009
mac-in-the-mountains wrote:
> Can anyone help me figure this one out.
> I have a form which contains two text areas 'start-date' and 'finish-date'.
> Ideally when filled in with a date (eg 2009-03-16 they will update the relevant
> records in the database (MySQL 'date' fields).
....

> But when I submit the form I get this message:
>
> 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 '-date='2009-01-30'
> WHERE id=2679' at line 1
>
> I've tried everything I can think of but I can't get it to work.

Without testing anything out, I think that the problem is the names of your columns. Having column names with spaces, dashes and other "special" characters will cause issues, unless you use the back tick character ( ` ) around your column names in the SQL like so:
$updateSQL = sprintf("UPDATE dates08 SET `start-date`=%s, `finish-date`=%s WHERE id=%s",

Of course, a better fix would be to change your column names to not have special characters in them so you don't have this issue again.

--
Danilo Celic
| http://blog.extensioneering.com/
| WebAssist Extensioneer
| Adobe Community Expert
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 17, 2009 Mar 17, 2009
LATEST
Perfect thanks

I went for the back ticks option as the column names are engrained too deeply in the rest if the site for me to change them now. But the back ticks did the trick first time.

Cheers

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines