I need the right syntax for MySQL trigger:
CREATE TRIGGER `parent_comm`
BEFORE UPDATE ON `employee` FOR EACH ROW
BEGIN
SET NEW.`parent_com`=(NEW.`com_amt`*10/100)
WHERE `id` = NEW.`parent_id`
END;
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 'WHERE id = NEW.parent_id
END' at line 5
Related
//my update query
$query = "UPDATE articles SET
title='$title',
author='$author',
body='$body'
WHERE id = {$uid}";
Error
ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 5
Now, I using mysqli extension with PHP.
this is my code:
TableName::db()->updateAll(array('updated' => 'NOW()'), "WHERE userID
= ". (string)$id);
This is the errormessage i get:
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL
syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near 'WHERE userID = 1043' at line
1. The SQL statement executed was: UPDATE TableName SET updated=:yp0 WHERE WHERE userID = 1043;. Bound with :yp0='NOW()'
The SQL Update Query will succesfully executed, but i want to fix this error.
Somebody have a hint for me how to fix this error?
Solution:
TableName::model()->updateAll(array('updated' => new CDbExpression('NOW()')), "userID= ". (string)$id);
The SQL Update Query will succesfully. Good luck to you
I am trying to find Payouts where user_id equals 1 from the skyrim table along with it's relations.
The code I executed is:
$user_payout = Payout::fromTable('skyrim')->where('user_id',1)->with('game','cluster')->first();
dd($user_payout);
It gives me this error:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where user_id = ? limit 1' at line 1 (SQL: select * where user_id = 1 limit 1)
Any reason why this doesn't work?
Try to fetch the data first then do the eager loading of relations
$model = (new Payout)->setTable('skyrim')->where('user_id', 1)->first();
if($model) {
$model->load('game','cluster');
}
I am trying to enter data into my MySQL database using the following query
UPDATE `Customer Table` SET `ID`=$ID, `First name`='$FirstName',`Last name`='$LastName',`Home phone number`=$HomePhoneNumber,`Mobile phone number`=$MobilePhoneNumber,`House number`=$HouseNumber,`House name`='$HouseName',`Street name`='$StreetName',`Town name`='$TownName',`Post code`='$PostCode' ,`Notes`='$Notes' WHERE ID=$ID
This is working fine when I'm calling it from one PHP file but not working when I'm calling it from an API PHP file.
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 '`House number`=0,`House name`='43',`Street name`='Westbury',`Town name`='We' at line 1
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 '`House number`=0,`House name`='3',`Street name`='Close',`Town name`='Thorn' at line 1
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 '`House number`=0,`House name`='flat',`Street name`='2 road',`Town ' at line 1
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 '`House number`=0,`House name`='39',`Street name`='valley',`Town name`='',`' at line 1
Can anyone see where the error is as I'm struggling to find it. All of the data types are correct from what I can see.
Thanks in advance, Luke.
Try this. It seems that your variable $MobilePhoneNumber contains string part within it something like +
"UPDATE `Customer Table` SET `ID` = '$ID', `First name` = '$FirstName',
`Last name`= '$LastName',`Home phone number`= '$HomePhoneNumber',
`Mobile phone number` = '$MobilePhoneNumber',`House number` = '$HouseNumber',
`House name`='$HouseName',`Street name`='$StreetName',`Town name`='$TownName',
`Post code`='$PostCode',`Notes`='$Notes' WHERE ID=$ID"
Gordon Linoff suggestions was best, $MobilePhoneNumber was not being read from my XML file.+ "<MobilePhoneNumber>" + MobileNumber + "</MobileNumber> was being written instead of + "<MobilePhoneNumber>" + MobileNumber + "</MobilePhoneNumber>
I'm getting MySQL error 42000:1064 that suggests a general syntax error with the following SQL:
UPDATE `events` SET ?=?, ?=?, ?=now() WHERE `event_id`=?;
PHP code to convert to a readable statement & also execute:
<?php
$ar = array_fill(0,count($args),'/\?/');
echo preg_replace($ar,$args,$sql,1);
$this->execute($sql, $args);
?>
This evaluates to:
UPDATE `events` SET event_name=test, form_id=webform, last_updated=now() WHERE `event_id`=124;
Which when pasted into the MySQL workbench completes successfully.
[mysqlErrorMsg] => SQLSTATE[42000]: Syntax error or access violation: 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 ''event_name'='test', 'form_id'='webform', 'last_updated'=now() WHERE `event_id`=' at line 1
It should be noted that my user has full access to the table in question.
You can't use placeholders on column names. Only on values.
Your query does NOT evaluate to (as it should)
UPDATE `events` SET event_name=test, form_id=webform, last_updated=now()
WHERE `event_id`=124;
but is being evaluated as this instead:
UPDATE `events` SET 'event_name'='test', 'form_id'='webform', 'last_updated'=now()
WHERE `event_id`=124;
See the quotes? These are strings, not column names.
So hard code the column names and only use placeholders for values
UPDATE `events` SET event_name=?, form_id=?, last_updated=now() WHERE `event_id`=?;