1

Very newb.

Have the following

cursor = db.cursor()
cursor.execute("SELECT email,id FROM list")
userData = cursor.fetchall()
cursor.execute("INSERT INTO campaigns(date) VALUES('Now')")

the first part works, the second does not (realize it wouldn't enter actual datetime), just trying to see if it will insert into database.

Why doesn't this work? I'm hoping to avoid having many db. entries with same username/passes.

I figured it would work? userData would contain what I want, and then cursor.execute would do afterwards.

Thanks!

[edit]

I actually tried to just do an insert statement by itself, and its not working?!? Any reason this should NOT work?

import mysqldb

db = MySQLdb.connect(host="host", port=3306, user="python", passwd="test", db="python")
cursor = db.cursor()
sql = "INSERT INTO campaigns(date) VALUES ('est')"
cursor.execute(sql)

The above code the SELECT statement works fine.

5
  • Can you post the error? and please look at : dev.mysql.com/doc/refman/5.6/en/insert.html and dev.mysql.com/doc/refman/5.5/en/…, this may fix your problem, replacing 'now' with NOW(). Commented May 3, 2014 at 7:36
  • there is no error...it just doesnt make a new entry. Commented May 3, 2014 at 17:34
  • I've actually just tried doing my single insert statement--and that is not working. Have no idea why. Tried logging in to phpMyAdmin under user/pass that my python program uses, and used exact same sql statement, and it works!? Commented May 3, 2014 at 23:16
  • can you take a look at my above edits? Commented May 3, 2014 at 23:19
  • got it figured out. needed to do db.commit() Commented May 3, 2014 at 23:27

1 Answer 1

2

Solution was that I needed to do db.commit()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.