Skip navigation links

MySQL Forums :: Connector/Python :: inserting values from python into mysql


Advanced Search

inserting values from python into mysql
Posted by: John Daily ()
Date: May 18, 2009 02:08AM

Hi guys i have a problem with my coding which i need help in.
i need to insert data from the form eg first name, last name, password etc into mysql:
<TR>
<TD><span>First name&nbsp;&nbsp;<font color="red">*</font></span></TD>
<TD><input type="text" class="text" maxlength="32" name="first_name"
value=""/></TD
</TR>
<TR>
<TD><span>Last name&nbsp;&nbsp;<font color="red">*</font></span></TD>
<TD><input type="text" class="text" maxlength="32" name="last_name"
value=""/></TD>
</TR>

so now im trying to get these values and store it into mysql user table.

>>db = MySQLdb.connect("123.12.3.12", "asda",
"helloworld", "qwerty", 3306)
>>c = db.cursor ()
>>sql = ("INSERT INTO user (first_name, last_name, gender, birth_year,
quote, user_name, user_password) VALUES (%s, %s, %s, %s, %s, %s, %s)");
>>"Account created for", user_name
>>sys.exit(1)
>>c.execute(sql)
>>c.close ()
>>db.commit()
>>db.close ()
>><html>
>><p>Please login <a href='home.py'><b>here</b></a>.</p>
>></html>

is this code right concerned with connecting python and mysql, inserting the values?

Options: ReplyQuote


Subject Written By Posted
inserting values from python into mysql John Daily 05/18/2009 02:08AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.