0

Are we using a different version of Flask, SQLite or PHPliteadmin in 2017?

Why are the codes i'm seeing in the web so different from mine..?

Mainly, the $ sign, I've never used a single $.. Unless I'm missing something here...?

Web:

<?php
    // configuration
    require("../includes/config.php");
    // if form was submitted
    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
        if(empty($_POST["username"]))
        {
            apologize("Invalid Username");
        }
        else if(empty($_POST["password"]))
        {
            apologize("Invalid Password");
        }
        else if($_POST["confirmation"] != $_POST["password"])
        {
            apologize("Passwords donot match");
        }
        else
        {

            $result = query("INSERT INTO users (username,hash,cash) VALUES(?,?,10000.00)",$_POST["username"],crypt($_POST["password"]));
            if($result === false)
            {
                apologize("Username already taken");
            }
            else
            {
                $rows = query("SELECT LAST_INSERT_ID() AS id");
                $id = $rows[0]["id"];
                $_SESSION["id"] = $id;
                redirect("./");
            }        
        }
    }
    else
    {
        // else render form
        render("register_form.php", ["title" => "Register"]);
    }
?>

Mine:

@app.route("/register", methods=["GET", "POST"])
def register():
    """Register user."""
    session.clear()

    if request.method == "POST":

        if not request.form.get("username"):
            return apology("must provide username")

        elif not request.form.get("password"):
            return apology("must provide password")

    #access information user has submitted in python route, request.form.get("name")
            return apology("must provide confirmation password")


        elif request.form.get("confirmation") != request.form.get("password"):
            return apology("password and confirmation does not match")


        pword = pwd_context.encrypt(request.form.get("password"))
        exist = db.execute("SELECT * FROM users WHERE username = :username", username=request.form.get("username"))
        if exist:
            return apology("username is taken")
        db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash = pword)
        new = db.execute("SELECT * FROM users WHERE username = :username", username=request.form.get("username"))
        session["user_id"] = new[0]["id"]

        return redirect(url_for("index"))

    else:
        return render_template("register.html") 
3
  • Where is "in the web"? That is last year's version of the pset that used php. This year python is used. May 7 '17 at 20:56
  • Oh, so we'll have less archive on people asking pset7 questions using python then... :(
    – nvs0000
    May 8 '17 at 17:04
  • There's nearly 100 questions on pset7 asked this year. Maybe click the "newest" option after your search. May 8 '17 at 19:06
0

I see, so there Is a change in what they were using before.. That's why its so confusing when i have a question and search for pset 7.. Thanks everyone. Will close this now..

-2

The instructions hosted at CS50's CDN have been recently updated. Problem Set 7 now uses PHP instead of Python, just as they had done in prior years.

In PHP, all variables must begin with the symbol $.

Hopefully, CS50 staff will make available for reference the instructions for solving the problem set via Python. Even though I find Python to be less portable due to its dependencies, it is widely used for Machine Learning and Data Science.

1
  • THIS ANSWER IS WRONG, please delete it! The posted link is the to Harvard 2015/CS50x 2016 pset http://cdn.cs50.net/2015/fall/psets/7/pset7/pset7.html, which was in PHP. The current version of the course CS50x 2017 http://docs.cs50.net/problems/finance/finance.html uses python not php. May 10 '17 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .