UPDATE dondathang
SET noigiaohang=diachi
FROM khachhang
WHERE dondathang.makhachhang=khachhang.makhachhang AND noigiaohang IS NULL;
I have a SQL code like above, but this is the error.
syntax error 'from' identifier is not valid input at this position.
What's wrong with my code?
FROM clause is irrelevant in UPDATE sintax. Please take a look at the documentation.
FROM Clause is not a part of UPDATE syntax, you can change the UPDATE as below
UPDATE dondathang
SET noigiaohang=diachi
JOIN khachhang ON dondathang.makhachhang=khachhang.makhachhang
WHERE noigiaohang IS NULL;
The correct syntax in MySQL is:
UPDATE dondathang d JOIN
khachhang k
ON d.makhachhang = k.makhachhang
SET d.noigiaohang = k.diachi
WHERE d.noigiaohang IS NULL;
Related
Can anyone tell me why this doesnt work, and returns syntax error please?
$sql4 = "update apiStreetCheckGeneral
set (BBAverageSpeed, BBSuperFastBBAvailable, BBCommentary)
values ('$averagespeed', '$superfast', '$bbcommentary')
where PostCode='".$values['PostCode']."'";
CustomQuery($sql4);
This is your query:
update apiStreetCheckGeneral set (BBAverageSpeed, BBSuperFastBBAvailable, BBCommentary)
values ('$averagespeed', '$superfast', '$bbcommentary')
where PostCode='".$values['PostCode'].
I am not aware of update syntax that uses a column list or values. Set each one individually:
update apiStreetCheckGeneral
set BBAverageSpeed = '$averagespeed',
BBSuperFastBBAvailable = '$superfast',
BBCommentary = '$bbcommentary'
where PostCode='".$values['PostCode']."'"
You should learn, however, to use parameterized queries especially for update statements.
Use query like below
$sql4 = "update apiStreetCheckGeneral
set BBAverageSpeed = '$averagespeed',
BBSuperFastBBAvailable = '$superfast',
BBCommentary = '$bbcommentary'
where PostCode='".$values['PostCode']."' ";
CustomQuery($sql4);
I am having a problem with my mysql statement.
basically the code works perfectly when inserting, but as soon as the addnew variable=false and it switches to update it gives me an error that i cannot solve.
The Code:
procedure Tadddomain.BitBtn2Click(Sender: TObject);
Var
PrevSql:String;
ID:String;
begin
With Datalive.domains Do
Begin
id:=fieldbyname('id').AsString;
Active:=False;
prevsql:=sql.Text;
Sql.Clear;
Params.Clear;
Addparam(Datalive.domains,'client_id',ftinteger,datalive.clients.FieldByName('id').AsString);
Addparam(Datalive.domains,'domain_name',ftString,Edit1.Text);
Addparam(Datalive.domains,'register_date',ftdate,DateTimePicker1.Date);
Addparam(Datalive.domains,'registered_until',ftdate,DateTimePicker2.Date);
if addnew=true then
Sql.Text:='Insert into domains (client_id,domain_name,register_date,registered_until) VALUES (:client_id,:domain_name,:register_date,:registered_until)'
Else if addnew=False then
Sql.Text:='Update domains (domain_name=:domain_name, register_date=:register_date, registered_until=:registered_until) where id='''+id+'''';
Showmessage(sql.text);
execsql;
sleep(100);
sql.Text:=prevsql;
active:=True;
done:=True;
adddomain.Close;
End;
end;
The Error:
Project project1.exe raised exception class EZSQLException with message 'SQL Error: 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 '(domain_name='asd',register_date='2014-11-09',registered_until='2015-11-09') w' at line 1'.
Any Assistance would be great, I have searched and searched and cannot find the fault.
Update:
I changed the edit code as suggested below, and now no errors apear what so ever. But also nothing happens. It does not edit the record.
if addnew=true then
Sql.Text:='Insert into domains (client_id,domain_name,register_date,registered_until) VALUES (:client_id,:domain_name,:register_date,:registered_until)'
Else if addnew=False then
Begin
sql.Add('Update domains');
sql.Add('set domain_name=:domain_name,');
sql.Add('register_date=:register_date,');
sql.Add('registered_until=:registered_until');
sql.Add('where id=:id');
End;
Update syntax is like this
Update domains
set domain_name = :domain_name,
register_date = :register_date,
registered_until = :registered_until
where id = :id
You declare the "client_id" parameter not the "id" parameter you use in the update statement.
where id = :id
should be
where id = :client_id
I have found the problem.
If i define the parameters before i use the sql.add() function the parameters are discarded.
When I moved the
Addparam(Datalive.domains,'client_id',ftinteger,datalive.clients.FieldByName('id').AsString);
Addparam(Datalive.domains,'domain_name',ftString,Edit1.Text);
Addparam(Datalive.domains,'register_date',ftdate,DateTimePicker1.Date);
Addparam(Datalive.domains,'registered_until',ftdate,DateTimePicker2.Date);
to just before the execsql; the problem was solved.
I am trying this but it doesn't work
update tb_traffic_log
set
c_status = 'Detected'
where
c_file_name = 'tj-sms-20122807-0956-000.log’;
kindly help
maybe you have a typo error, you are not using single quote on the value
update tb_traffic_log
set c_status='Detected'
where c_file_name='tj-sms-20122807-0956-000.log’;
^ HERE
change it to 'tj-sms-20122807-0956-000.log'
Ohh i got the error:
Its the closing quote before the semicolon:
c_file_name = 'tj-sms-20122807-0956-000.log’;
should be
c_file_name = 'tj-sms-20122807-0956-000.log';
just having some trouble with an SQL update in PHP. Listed below is an extract of the function:
$captain = $this->getUserName();
$member = $textParts[1];
$memberNo = 'member1';
$sqlUpdate = 'UPDATE ajax_chat_draft_teams SET '.$memberNo.'='.$member.' WHERE captain='.$captain.'';
$result = $this->db->sqlQuery($sqlUpdate);
When the Query is reached it throws the following error:
Query: UPDATE ajax_chat_draft_teams SET member1=user WHERE captain=Oolius
Error-Report: Unknown column 'Oolius' in 'where clause'
Error-Code: 1054 error occured!
The table ajax_chat_draft_teams has 5 fields: captain, member1, member2, member3, member4
(Note: There is a record in the table where the captain is Oolius and all members are NULL).
I'm failing to see what is wrong with my SQL statement. Thanks for your time.
Try this:
$sqlUpdate = 'UPDATE ajax_chat_draft_teams SET '.$memberNo.' = "'.$member.'" WHERE captain = "'.$captain.'"';
String literals need to be surrounded in single quotes. The query should look like this:
UPDATE ajax_chat_draft_teams SET member1='user' WHERE captain = 'Oolius'
Also, consider using PDO and bind variables.
You need to put Oolius in quotes other MySQL thinks it is a column name.
Use this
$sqlUpdate = 'UPDATE ajax_chat_draft_teams SET
'.$memberNo.'="'.$member.'" WHERE captain="'.$captain.'"';
i hope it will help you.
I'm new to CodeIgniter and I get an error I cannot understand.
This is the code that give the error:
$data = array('adr' => $address);
$this->db->where('id', $id);
$this->db->update('domains', $data);
The error is:
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 '://www.example.com WHERE id = '10'' at line 1
This is the query:
UPDATE `domains` SET `adr` = http://www.example.com WHERE `id` = '10'
If I change this to
UPDATE `domains` SET `adr` = 'http://www.example.com' WHERE `id` = '10'
it works. Why is CodeIgniter creating this erroneous query?
Try escaping the single quotes in the $address variable before you call the update method.
Generally the CodeIgniter will automatically surround the value of $address with a single quote. I do not know why did you get this error message?
Curious, see if it works when you escape the string use $this->db->escape()
$data = array('adr' => $this->db->escape($address));
$this->db->where('id', $id);
$this->db->update('domains', $data);
I have the same problem and codeigniter do not add single qoutes to where clause.
When you enter integer value, sql do not give error but when you put string value (as a variable) to where clause, it gives error. But when you add single quotes to query and run it on phpmyadmin, it works.
So the solution is adding (string) statement to your variable: as in this (string)$id
I wrote before to add single quotes to variable as '$id', but this will not going to work (I'm new to codeigniter&php, thanks to commenter Mitchell McKenna, I checked out what I wrote before)