Click here to Skip to main content
14,266,228 members
Rate this:
Please Sign up or sign in to vote.
import mysql.connector
from mysql.connector import Error
from mysql.connector import errorcode
import socket
#get IP from computer
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
dataIP = (s.getsockname()[0])
s.close()
#set connection with sql
mydb = mysql.connector.connect(
      host= "localhost",
      user = "root",
      passwd ="",
      database="iqtakon"
)
mycursor = mydb.cursor()
sql = "insert into tbluser (txtIP) values('"+dataIP+"')"
mycursor.execute(sql)
if dataIP == None:
    print("on connection")
else:
    print("have connection")
print(dataIP)


What I have tried:

i try on this code to insert but no insert to database and have check database set to online txtIP .
Posted
Updated 3-Jul-19 4:00am
Comments
Dominic Burford 3-Jul-19 3:28am
   
Are you getting an error? Do you have error logs you can check? Do you have a valid connection? Is your INSERT statement correct? I have no idea what has failed without you providing more detail.
Member 11271238 3-Jul-19 5:11am
   
i forget with mydb.commint() i see my problem, thank you

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

As you mentioned in the comments, you have fixed this by using mydb.commit(). Adding this solution so that this question no longer shows in the Unanswered queue.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100