dossbob
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.
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.
ASKER
Sadly, no. I tried the syntax below, but got the same error message.
UPDATE `bookings` SET `availability` = 'xx' WHERE `bookings_id` = '2002'
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).
maybe the sql variable has something in it left over from the previous query(ies).
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.
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 =)
We need to see the codeigniter code =)
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);
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
}
ASKER
DUH!
It's always SOOO obvious after someone else sees it for you!
Thanks for my latest lesson in humility (:>)
UPDATE `bookings` SET `availability` = 'xx' WHERE `bookings_id` = '2002';