Click here to Skip to main content
16,017,151 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
use test
-- insert
INSERT INTO cust VALUES ('hi');


-- fetch 
SELECT * FROM cust

 

test is my database name cust is my table name have only 1 column varchar 

getting error code 1064 you have an error in syntax


What I have tried:

syntax is correct but still showing syntax incorrect
Posted
Updated 8-May-23 13:13pm
Comments
Richard MacCutchan 5-May-23 4:18am    
I have just run those exact commands on my test db and it works correctly. Please update your question with the complete script that you use and the actual output from when you run it.

We can't access your database, and we don't know how you are issuing those commands: you could be using a DB Management tool or code in PHP, Python, C#, ... and that could be impacting on the problem you are seeing. Or it could just be that you typed it into your question here and it's different in your actual query.

So start by breaking it up: Execute just the USE and INSERT lines, and see if the error persists. If it doesn't, it's in the SELECT, so execute just the USE and SELECT and see what happens.
If it does, then look at the actual database table and see what it currently holds.

Basically, narrow down your problem: find which part is causing the problem first and it may be more obvious what is going on.

Sorry, but we can't do any of that for you!
 
Share this answer
 
Suggest you log out/in start a fresh session then start again, copy/paste the entire session if error(s) still persist.

I've re-created a session attempting to mimic yours .... the log of that follows ....


OS - linux mint 20.x
mysql - version 8.0.33 ....


mysql -u $USER
mysql> use junkdb;
Database changed

mysql> describe cust;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| stuff | varchar(255) | NO   |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql> select * from cust;
Empty set (0.00 sec)

mysql> INSERT INTO cust VALUES ('hi');
Query OK, 1 row affected (0.01 sec)

mysql> SELECT * FROM cust;
+-------+
| stuff |
+-------+
| hi    |
+-------+
1 row in set (0.00 sec)

mysql> exit;
Bye
 
Share this answer
 

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