0

I am trying to make a recipe blogging platform, but whenever I pass in values to the database, it gives me a runtime error. The problem is with the 'text' column, as whenever there is a newline in the recipe, the error appears. However, when the recipe is a single line, then there is no error. How do I fix this?

        title = request.form.get("title")
        recipe = request.form.get("recipe")
        imageURL = str(request.form.get("image"))
        meal = request.form.get("meal")

        if not title or not recipe or not imageURL or not meal:
            return apology("Please enter a value in all fields")

        user = session['user_id']

        characters = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"
        url = ""

        for i in range(10):
            url += characters[random.randint(0, len(characters) - 1)]

        while (db.execute(f"SELECT * FROM recipes WHERE url = '{url}';")) != []:
            url = ""

            for i in range(10):
                url += characters[random.randint(0, len(characters) - 1)]

        username = db.execute(f"SELECT * FROM users WHERE id = {user};")[0]["username"]

        db.execute(f"INSERT INTO recipes (id, username, title, text, url, image, meal) VALUES ({user}, '{username}', '{title}', '{recipe}', '{url}', '{imageURL}', '{meal}');")
        return redirect("/")
1

You must log in to answer this question.

Browse other questions tagged .