Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MySQLdb

0 views
Skip to first unread message

Kill Joy

unread,
Nov 22, 2009, 9:36:09 AM11/22/09
to
Hi all.

I have a mod_python script with two query:

cursor = db.cursor()

sql = 'SELECT * FROM users where username=\'' + username +'\''
cursor.execute(sql)
result = cursor.fetchall()
num = int(cursor.rowcount)

if num == 0 :
sql2 = 'insert into users values (null, \'' + username + '\', \'' +
password +'\', \'no\',\'fdfdf\')'
cursor.execute(sql2)
warning = "Registration ok"
else :
warning = "EXIST!"

The first query is executed... but not the second. It doesn't insert.
Why?
I'm a newbie... sorry.

Many thanks.


K

Gerald Walker

unread,
Nov 22, 2009, 10:00:03 AM11/22/09
to
Kill Joy wrote:
> Hi all.
>
> I have a mod_python script with two query:
>
> cursor = db.cursor()
>
> sql = 'SELECT * FROM users where username=\'' + username +'\''
> cursor.execute(sql)
> result = cursor.fetchall()
> num = int(cursor.rowcount)
>
> if num == 0 :
> sql2 = 'insert into users values (null, \'' + username + '\', \'' +
> password +'\', \'no\',\'fdfdf\')'
> cursor.execute(sql2)
db.commit()

> warning = "Registration ok"
>
> else :
> warning = "EXIST!"
>
> The first query is executed... but not the second. It doesn't insert.
> Why?
> I'm a newbie... sorry.
>
> Many thanks.
>

I added db.commit() after cursor.execute(sql2).

Kill Joy

unread,
Nov 22, 2009, 10:03:18 AM11/22/09
to

ohhh... many thanks many thanks.

Gius.

Message has been deleted
0 new messages