0
How to fix MySQL with python issue
import mysql.connector as c try: conn=c.connect(user="root", password="Na1*xq#P", host="localhost", port=3306, database="abrs") if conn.is_connected(): print("Database Connection Successful...") except: print("Unable to connect!!!") myc=conn.cursor() id=input("Enter your id: ") name=input("Enter your name: ") phoneno=input("Enter your phoneno: ") InsertT="Insert into customer values ('{}','{}',{}')".format(id, name, phoneno) myc.execute(InsertT) conn.commit() print("Data inserted successfully...") myc.close() conn.close()
19 Answers
+ 3
I am glad I could help.
I am from Hungary.
+ 3
I am only a hobbyist in programming. I actually work with Oracle database a lot so I am good with SQL.
I learned many languages since I was a kid. On Sololearn I picked up Python, and since then, Kotlin became one of my favorites.
You can browse the codes under my profile to see what I do.. I write mostly Kotlin these days, but I know Java, C#, JavaScript, Python, PHP, C++, Scala, Haskell, Clojure to varying degree. My top favourite language is Clojure.
+ 2
What is the issue you have? Any error messages?
My first guess is that ID column in the SQL table is usually numeric but you try to insert a string.
+ 2
The code will not work without a mysql database and the tables created the same way as they are on your system.
Here is a link explaining your error.
https://kinsta.com/knowledgebase/mysql-error-1064/#:~:text=The%20MySQL%201064%20error%20is,between%20you%20and%20your%20database.
+ 2
Check carefully your insert statement. I think an apostrophe is missing.
+ 2
InsertT="Insert into customer values ('{}','{}','{}')".format(id, name, phoneno)
I added the apostrophe.
+ 1
Oh I see beside curley braces . Oh man Thankyou. Let me try does it help me to fix it.
+ 1
Where are you from my friend. If you don't mind to answer. Thankyou very much to fix it . Now code is perfectly working and data inserted successfully. Once again thankyou
0
Error is 1064 . Can you copy and run this program . PLZ and tell me where it is going wrong.
0
What I am trying to do is to take input from user and according insert data inside
0
I had already created a table and database
0
Database name abrs . Table name customer and columns are id , name , phone no
0
Where my friend
0
I am beginner . So don't know how to fix it.
0
How to message each other in this sololearn . Asking me to confirm your email id. But I didn't received an email .
0
May I know you are expert in which areas ( Programing Languages)
0
👍👌👏👏. You know many languages
0
In my opinion your id is an int not string. And you have missed one comma in insertT line..
0
He helped me to fix it . Thankyou for suggestions