0
<?php

    // configuration
    require("../includes/config.php");

    // if user reached page via GET (as by clicking a link or via redirect)
    if ($_SERVER["REQUEST_METHOD"] == "GET")
    {
        // else render form
        render("register_form.php", ["title" => "Register"]);
    }

    // else if user reached page via POST (as by submitting a form via POST)
    else if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
         // validate submission
        if (empty($_POST["username"]))
        {
            apologize("You must provide your username.");
        }
      if (empty($_POST["password"]))
        {
            apologize("You must provide your password.");
        }
         if( empty($_POST["confirm-password"]))
        {
            apologize("Please enter the password again");
        }
         if( $_POST["password"] != $_POST["confirm-password"] )
        {
            apologize("Please enter the same password as above");
        }
       else
        {
            $result = CS50::query("SELECT * FROM users WHERE username = ?",$_POST["username"]);
            if($result == true)
                apologize("Username already exists");
            else
                $result = CS50::query("INSERT INTO users(username,hash,cash) VALUES (?,?,10000)",$_POST["username"],crypt($_POST["password"]));
                $rows = CS50::query("SELECT LAST_INSERT_ID() AS id");
                $id = $rows[0]["id"];
                $_SESSION["id"];
        }


    }

?>
1

Change the last line of code to $_SESSION["id"] = $id;

You must log in to answer this question.

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