Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Fatal error: Uncaught mysqli_sql_exception: 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 'UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END'




Code:
dbquery("SET @num = (SELECT COUNT(*) AS num FROM dispatchersonduty); UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END", false);


What I have tried:

looking up on google and nothing.
Posted
Updated 10-Mar-22 21:24pm
v2
Comments
CHill60 7-Mar-22 6:12am    
MySQL or MariaDB? Post your actual code not just the error message

At a guess, your custom dbquery method doesn't support multiple statements in a single query. In general, PHP requires special handling for multi-statement queries:

PHP: Multiple Statements - Manual[^]
 
Share this answer
 
Comments
Mtag Gaming 11-Mar-22 3:39am    
copy that
We can't help you: we can't see your code, or access your database - and you probably need both in order to work out what is wrong.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google should give you the info you need: php debugger - Google Search[^]

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Mtag Gaming 10-Mar-22 9:55am    
dbquery("SET @num = (SELECT COUNT(*) AS num FROM dispatchersonduty); UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END", false);
UPDATE SQL Syntax for normal cases is like

SQL
UPDATE <table_name>
SET <column_name> = <value>
[WHERE <condition> ]


Your update SQL
SQL
UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END

is Clearly Erroneous because your table name and column name are same.
 
Share this answer
 
v3
Comments
CHill60 7-Mar-22 6:10am    
There is nothing wrong with having a column name with the same name as the table. For example this SQL is perfectly valid
create table signal100(signal100int);
insert into signal100(signal100) values (1),(2),(3);
update signal100 set signal100= 4 where signal100= 2;
_Asif_ 7-Mar-22 6:58am    
You are right, This is new to me. Logically it does not make sense.
+5
CHill60 7-Mar-22 7:57am    
:laugh: I never said it made sense - we are in QA after all!
The error message suggest that you check the documentation: UPDATE - MariaDB Knowledge Base[^]
 
Share this answer
 
Now that you have finally shared your code I can tell you that you have omitted a semi-colon after END.
dbquery("SET @num = (SELECT COUNT(*) AS num FROM dispatchersonduty); UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END;", false);
 
Share this answer
 
Comments
Mtag Gaming 10-Mar-22 14:35pm    
I don't know why its there on my code I don't have a semi-colon after end

dbquery("SET @num = (SELECT COUNT(*) AS num FROM dispatchersonduty); UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END" , false);
CHill60 10-Mar-22 14:57pm    
I know you don't have a semi-colon after END. That is the problem, there should be one!
Mtag Gaming 10-Mar-22 15:37pm    
okay, its in the code and I'm still getting the error
CHill60 10-Mar-22 16:36pm    
Post your amended code here
Mtag Gaming 10-Mar-22 16:47pm    
dbquery("SET @num = (SELECT COUNT(*) AS num FROM dispatchersonduty); UPDATE signal100 SET signal100 = CASE WHEN @num > 0 THEN signal100 ELSE 0 END;" , false);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900