Insert data into MySQL from HTML Form using .psp script

brianrpsgt1

Usenet Archive
Joined
Nov 24, 2007
Messages
18
Reaction score
0
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the MySQL Insert statement. I am familiar with PHP, where you would write $_POST(['field']), however I can not find the equivalent in PSP. I believe that this is the my missing piece. Technically, what is occurring that that when I click the 'Submit' button, it is inserting NULL field values into the db.

Sample code is below ::

HTML FORM CODE

<html>
<head>
<link rel="stylesheet" type="text/css" href="./styles/
projectpage.css">
</head>

<h2>PAGE</h2>
<form name="input_form" action="insert_go.psp" method="post"> <input type="text" name="date" id="date"> <br>
Time:
<input type="text" name="time" id="time">
<br>
Activity:
<input type="textarea" rows="20" cols="40" name="activity" id="activity"> <br>
Next Steps:
<input type="textarea" rows="20" cols="40" name="notes" id="notes"> <br> <input type="submit" value="Submit"> </form> </html>

Below is the psp script

<%
import MySQLdb

host = 'localhost'
user = 'user'
passwd = 'somepass'
db = 'MyDB'

conn = MySQLdb.connect(host, user, passwd, db)
mysql = conn.cursor

sql = ("""INSERT INTO activity VALUES (date,time,activity,notes);""");

mysql.execute(sql)

conn.commit
mysql.close
conn.close
%>

<html>
<p>Sucess!</p>
</html>

Thanks for any assistance.

B
 

Tino Wildenhain

Usenet Archive
Joined
Sep 18, 2008
Messages
159
Reaction score
0
brianrpsgt1 wrote:
I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the MySQL Insert statement. I am familiar with PHP, where you would write $_POST(['field']), however I can not find the equivalent in PSP. I believe that this is the my missing piece. Technically, what is occurring that that when I click the 'Submit' button, it is inserting NULL field values into the db.

wht is a PSP script? If you have that and good reason to use it you should have documentation, no? If not, just use something else you know or which comes with documentation.

Sample code is below ::

HTML FORM CODE

<html>
<head>
<link rel="stylesheet" type="text/css" href="./styles/
projectpage.css">
</head>

<h2>PAGE</h2>
<form name="input_form" action="insert_go.psp" method="post"> ...

I would not recommend this, no matter what PSP is. You are not only mixing code with HTML, you even mix HTML, code and SQL. This is strongly discouraged. Try to split your application into templating and core application and let the application deal with whatever your data storage is. Note there are plenty really good web frameworks with python which save you a great deal of the housekeeping, giving your more time to construct your application.

Regards
Tino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top