Python Forum
Python keeps inserting NULL values into table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python keeps inserting NULL values into table
#3
import os
import psycopg2

from flask import Flask, session, render_template, request
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker


app = Flask(__name__)

# Check for environment variable
if not os.getenv("DATABASE_URL"):
    raise RuntimeError("DATABASE_URL is not set")

DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')

# Configure session to use filesystem
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

# Set up database
engine = create_engine(os.getenv("DATABASE_URL"))
db = scoped_session(sessionmaker(bind=engine))


@app.route("/")
def index():
    return "Project 1: TODO"



try:
    connection = psycopg2.connect(user = "zpztmsdffwqvs",
                                  password = "16671705ed2adsfd7855f36cb8c05a5188abc7fd823c850e46625",
                                  host = "ec2-54-33-37-321.compute-1.amazonaws.com",
                                  port = "5432",
                                  database = "dafdafsdasd")

    cursor = connection.cursor()
    

except (Exception, psycopg2.Error) as error :
    print ("Error while connecting to PostgreSQL", error)
finally:
    #closing database connection.
        if(connection):
            cursor.close()
            connection.close()
            print("PostgreSQL connection is closed")
            
            
          
@app.route("/register", methods=["GET", "POST"])
def register():
    
    if request.method == "GET":
        return render_template("register.html")
    elif request.method == "POST":
        password = request.form.get("password")
        username = request.form.get("username")
        print (username)
        print (password)
        # session.clear()
        # db.execute("INSERT INTO users (username, password) VALUES (:username, :password)", {"username":username, "password":password})
        # db.commit()
        return render_template("register.html", message=username)

            
            

should i start a new thread?
Reply


Messages In This Thread
SQL not INSERTING into table - by card51shor - Jun-09-2020, 01:31 AM
RE: SQL not INSERTING into table - by Larz60+ - Jun-09-2020, 02:08 AM
RE: SQL not INSERTING into table - by card51shor - Jun-09-2020, 02:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with number of rows containing null values PythonSpeaker 3 2,304 Nov-23-2019, 06:53 PM
Last Post: ibreeden
  Issues with Inserting Values into an Empty List with a While Loop TommyMer 2 3,850 Sep-12-2018, 12:43 AM
Last Post: TommyMer
  file a table of values Ybivashka322 4 3,845 Dec-14-2017, 06:11 PM
Last Post: mpd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020