0

my register.php code seems to work (at least I do find the new user in the database table), however instead of reaching index.php, I get this errormessage:

https://ide50-felderer.cs50.io/register.php

enter image description here

Here's my code:

// 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")
{
    // TODO

    // validate submission
    if (empty($_POST["username"]))
    {
        apologize("You must provide your username.");
    }
    else if (empty($_POST["password"]))
    {
        apologize("You must provide your password.");
    }
    else if ($_POST["password"] != $_POST["confirmation"])
    {
        apologize("Passwords do not match.");
    }

    // insert new user to database
    $result = CS50::query("INSERT IGNORE INTO users (username, hash, cash) VALUES(?, ?, 10000.0000)", $_POST["username"], password_hash($_POST["password"], PASSWORD_DEFAULT));

    // apologize if insertion failed
    if ($result == 0)
    {
        apologize("Username already exists.");
    }

    // login new user and redirect to portfolio
    $rows = CS50::query("SELECT LAST_INSERT_ID() AS id)");
    $id = $rows[0]["id"];
    $_SESSION["id"] = $id;
    redirect("index.php");

}

Thanks in advance!

Karin

1

Shouldn't this:

$rows = CS50::query("SELECT LAST_INSERT_ID() AS id)");

be this?

$rows = CS50::query("SELECT LAST_INSERT_ID() AS id");
2
  • OMG! Thank you so much! I really shouldn't do any coding after midnight ;-). – kafe Dec 13 '16 at 23:54
  • It happens! But you had a good clue there in your screenshot when you were told the error was on line 42! Next time try to make the most of these error messages! – Yuri Laguardia Dec 13 '16 at 23:55

You must log in to answer this question.

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