0

I have a form which needs to be updated I get a sql error. Cant see whats going on with my sql statement in my class file. Need assistance in finding where the issue is.

public function update(){
    global $database;
$sql = "UPDATE ".self::$table_name." SET when = '{$database->mysql_prep($this->when)}', where = '{$database->mysql_prep($this->where)}', howmuch = '{$database->mysql_prep($this->howmuch)}', contact = '{$database->mysql_prep($this->contact)}', daytimephone = '{$database->mysql_prep($this->daytimephone)}', emailqueries = '{$database->mysql_prep($this->emailqueries)}', websiteurl = '{$database->mysql_prep($this->websiteurl)}', description = '{$database->mysql_prep($this->description)}' WHERE id='{$database->mysql_prep($this->id)}'";
    $database->query($sql);
    return ($database->affected_rows() == 1) ? true:false;
}
0

1 Answer 1

5

WHEN and WHERE are reserved keywords in MySQL. Enclose them in backticks if you need to use those as field names:

`where`
`when`
Sign up to request clarification or add additional context in comments.

3 Comments

So is when... its used with CASE
stupid formatting is messin' with yo' backicks - i fixed it up a bit, hope you dont mind :-)
@prodigitalson Yeah I just went through hell trying to make the backticks look good and keep code formatting... Thanks for editing! (-:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.