I am using Python CGI Scripting to get my user sign up form running on XAMPP server but It's giving me an error . also I am new to This Website so If Possible , Please comment how to make the code and error messages more readable . I had to manually enter double lines for readability because it was removing all the formatting and indentation .
Error is :
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: server.py
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.6
The HTML File's Code is :
<body>
<div id="wrapper">
<div id="login">
<h2>Welcome</h2>
<img src="media/login_icon.png" height="60px" width="auto">
<form action="server.py" enctype="text/plain" onSubmit="return validation()" method="post" name="signupForm">
<p>Username :</p>
<input type="text" size="33" id="userName" placeholder="username here" name="userName" required><span id="userResponse"> </span>
<p>Password :</p>
<input type="password" size="33" id="pass" placeholder="password here" name="password" required><span id="passwordResponse"> </span>
<p>Confirm Password :</p>
<input type="password" size="33" id="cPass" placeholder="password here" name="cPass" required><span id="cPassResponse"> </span>
<p>Email :</p>
<input type="email" size="33" id="email" placeholder="email here" name="email" required><span id="emailResponse"> </span>
<p>Phone Number :</p>
<input type="text" size="33" id="pNumber" placeholder="phone number here" name="pNumber" required><span id="pNumberResponse"> </span>
<br />
<button type="submit">Sign Up</button>
<p id="footer">Already Have an Account ?<a href="index.html">Login</a></p>
</form>
</div><!--End of Login Div-->
</div><!--End of Wrapper Div-->
</body>
And The server.py file is :
#!C:\Users\tushar\AppData\Local\Programs\Python\Python36-32\python.exe import cgi
import cgitb
import mysql.connector
cgitb.enable()
def htmlTop():
print("Content-type:text/html\n\n <DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title> My Server-side template</title></head><body>")
def htmlTail():
print("</body></html>")
def connectDB():
my=mysql.connector.connect(host='localhost' , user='root' , password='' , database='signUp')
c=my.cursor()
return my,c
def getData():
formData = cgi.FieldStorage()
userName = formData.getvalue("userName")
password = formData.getvalue("password")
email = formData.getvalue("email")
pNumber = formData.getvalue("pNumber")
dataList = (userName,password,email,pNumber)
return dataList
def createTable(my,c):
c.execute("CREATE TABLE IF NOT EXISTS signUp (ID INT AUTO_INCREMENT PRIMARY KEY,USERNAME VARCHAR[36] NOT NULL ,PASSWORD VARCHAR[36] NOT NULL , EMAIL VARCHAR[36] NOT NULL , PHONE_NUMBER VARCHAR[36] NOT NULL)")
my.commit()
def entry(my,c,dataList):
c.execute("INSERT INTO signUp (USERNAME , PASSWORD , EMAIL , PHONE_NUMBER) VALUES (%s %s %s %s)",dataList)
my.commit()
try:
htmlTop()
db,cursor = connectDB()
createTable(db,cursor)
dataList = getData()
entry(db,cursor,dataList)
htmlTail()
except:
cgi.print_exception()
Aucun commentaire:
Enregistrer un commentaire