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()

10th Jul 2022, 9:12 AM
Om Yele
Om Yele - avatar
19 Answers
+ 3
I am glad I could help. I am from Hungary.
10th Jul 2022, 1:35 PM
Tibor Santa
Tibor Santa - avatar
+ 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.
10th Jul 2022, 6:15 PM
Tibor Santa
Tibor Santa - avatar
+ 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.
10th Jul 2022, 9:34 AM
Tibor Santa
Tibor Santa - avatar
+ 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.
10th Jul 2022, 12:56 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Check carefully your insert statement. I think an apostrophe is missing.
10th Jul 2022, 12:58 PM
Tibor Santa
Tibor Santa - avatar
+ 2
InsertT="Insert into customer values ('{}','{}','{}')".format(id, name, phoneno) I added the apostrophe.
10th Jul 2022, 1:07 PM
Tibor Santa
Tibor Santa - avatar
+ 1
Oh I see beside curley braces . Oh man Thankyou. Let me try does it help me to fix it.
10th Jul 2022, 1:09 PM
Om Yele
Om Yele - avatar
+ 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
10th Jul 2022, 1:14 PM
Om Yele
Om Yele - avatar
0
Error is 1064 . Can you copy and run this program . PLZ and tell me where it is going wrong.
10th Jul 2022, 12:53 PM
Om Yele
Om Yele - avatar
0
What I am trying to do is to take input from user and according insert data inside
10th Jul 2022, 12:54 PM
Om Yele
Om Yele - avatar
0
I had already created a table and database
10th Jul 2022, 12:56 PM
Om Yele
Om Yele - avatar
0
Database name abrs . Table name customer and columns are id , name , phone no
10th Jul 2022, 12:58 PM
Om Yele
Om Yele - avatar
0
Where my friend
10th Jul 2022, 12:59 PM
Om Yele
Om Yele - avatar
0
I am beginner . So don't know how to fix it.
10th Jul 2022, 12:59 PM
Om Yele
Om Yele - avatar
0
How to message each other in this sololearn . Asking me to confirm your email id. But I didn't received an email .
10th Jul 2022, 1:00 PM
Om Yele
Om Yele - avatar
0
May I know you are expert in which areas ( Programing Languages)
10th Jul 2022, 1:37 PM
Om Yele
Om Yele - avatar
0
👍👌👏👏. You know many languages
11th Jul 2022, 1:59 AM
Om Yele
Om Yele - avatar
0
In my opinion your id is an int not string. And you have missed one comma in insertT line..
12th Jul 2022, 1:03 AM
SUDIP LAUDARI
SUDIP LAUDARI - avatar
0
He helped me to fix it . Thankyou for suggestions
12th Jul 2022, 3:25 AM
Om Yele
Om Yele - avatar