Link to home
Start Free TrialLog in
Avatar of dossbob
dossbobFlag for United States of America

asked on

MySQL 1064 error with apparently good syntax

On a Codeigniter/PHP/MySQL webpage, I'm getting a 1064 error, but my query syntax looks valid to me. Here's my query:

UPDATE bookings SET availability = 'xx' WHERE bookings_id = 2002;

. . . and here's the error 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 '1' at line 1

I don't think it's really a syntax error, but I don't know what else to look for.
Avatar of gamebits
gamebits
Flag of Canada image

try

UPDATE `bookings` SET `availability` = 'xx' WHERE `bookings_id` = '2002';
Avatar of dossbob

ASKER

Sadly, no. I tried the syntax below, but got the same error message.


UPDATE `bookings` SET `availability` = 'xx' WHERE `bookings_id` = '2002'
post code

maybe the sql variable has something in it left over from the previous query(ies).
Avatar of dossbob

ASKER

What do you mean by the "sql variable"?

If you mean the variable where I build the query, it's initialized immediately before I use it, and I echo the resulting string. That's what I'm pasting into this forum, so it should be exactly what the program is trying to use.

FWIW: I've stripped the program down to barebones, so there's nothing left to interfere with the definition and immediate execution of the query.

I can post the Codeigniter code if anyone wants to see it.
Sure post it.
The reason why I say post is because that error corresponds typically to codeigniter quirks. =nerdsoftech
are you using mysql_query opposed to mysql_select_db?

We need to see the codeigniter code =)
Avatar of dossbob

ASKER

Here's the entire function from the CI controller:

function check_availability()
{
   $sql = "UPDATE bookings SET availability = 'xx' WHERE bookings_id = '2002'";

   echo $sql . "<br>";

   $this->load->database();
   $query  = $this->db->query($sql);
   $this->db->query($query);
}
ASKER CERTIFIED SOLUTION
Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since $query is the result of your UPDATE sql query -- running it through another sql query will result in error (read below).

The result from an UPDATE query results in FALSE (0) if it fails -OR- TRUE (1) if it succeeds. Therefore running the RESULT through ANOTHER query results in the error:

#1064:
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 '1' at line 1

=nerdsoftech
function check_availability()
{
   $sql = "UPDATE bookings SET availability = 'xx' WHERE bookings_id = '2002'";

   echo $sql . "<br>";
   
   $this->load->database();
   $query = $this->db->query($sql);
   // $query is now "0" or "1" as the result of the UPDATE query
}

Open in new window

Avatar of dossbob

ASKER


DUH!


It's always SOOO obvious after someone else sees it for you!

Thanks for my latest lesson in humility (:>)