Skip to main content
Inspiring
March 16, 2009
Question

Problem with update record (PHP/My SQL)

  • March 16, 2009
  • 1 reply
  • 519 views
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.
This topic has been closed for replies.

1 reply

Inspiring
March 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
Inspiring
March 17, 2009
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