Python Coding in Blender

203 views Asked by At

can someone help me solve this problem?

I'm using Blender 2.74 and Python 3.4 with the correct connector for MySQL. (By the way, I'm just a beginner in using Blender and Python.)

What I want is to make a login UI and save the inputted name into the database, but my code seems a bit off or wrong. When I try to run the code, it didn't save the value in the variable, but when i try to run it in python IDE (PyCharm) it worked.

Here's the code:

import sys

sys.path.append('C:\Python34\Lib\site-packages')
sys.path.append('C:\Python34\DLLs')

import mysql.connector

import bge
bge.render.showMouse(1)

cont = bge.logic.getCurrentController()
own = cont.owner

sensor = cont.sensors ["enter"]
pname = own.get("prpText")

enter = cont.sensors ["enter"]
numpadenter = cont.sensors ["numpadenter"]

if enter.positive or numpadenter.positive:
    db = mysql.connector.connect(user='root', password='', host='localhost', database='dbname')

    cursor = db.cursor()

    cursor.execute("INSERT INTO tblname VALUE(%s", (pname))

#this are the other codes that i have tried so far:
#add_player = ("INSERT INTO storymode " "(PlayerName) " "VALUES (%s)")
#data_player = (pname)
#cursor.execute(add_player, data_player)

#cursor.execute("INSERT INTO storymode" "(PlayerName)" "VALUES (%(pname)s)")

db.commit()

db.close()  

The Error is:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your mysql server version for the right syntax to use near '%s' at line 1.

Can someone tell what i need to do here? Do I need some add-ons for it to work?

Thank you very much for reading my post and for the people who will give their opinions.

1

There are 1 answers

7
maxymoo On

Looks like you're missing a closing parenthesis and an 'S' in you're sql INSERT statement?

INSERT INTO tblname VALUE (%s

needs to be

INSERT INTO tblname VALUES (%s)