0

Trying to make register.php to insert a name, the checks work fine, as empty name, empty password an confirmation and password different from confirmation leads to apologize. Then if user already exists, it leads to apologize either, with the message User exists as i stated, but when i try to insert the user after all check i get this: Fatal error: Column count doesn't match value count at row 1 in /home/jharvard/vhosts/pset7/includes/functions.php on line 152. And the user is not included in the database.

    <?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")
{
    // TODO
if(empty($_POST["username"]))
{
    apologize("Bad user name.");
}
if(empty($_POST["password"]) || empty($_POST["confirmation"]))
{
    apologize("Bad password");
}   
if($_POST["password"] != $_POST["confirmation"])
{
    apologize("passwords doesn't match");
}
else
{
    $reslt = query("SELECT * FROM users WHERE username = ?", $_POST["username"]);
    if($reslt === true)
    {
        apologize("User exists");
    }
    else
    {
        $result = query("INSERT INTO users (username, hash, cash) VALUES(?, ?, 10000,00)", $_POST["username"], crypt($_POST["password"]));
        $rows = query("SELECT LAST_INSERT_ID() AS id");
        $id = $rows[0]["id"];
        $_SESSION["id"];
    }
}
}

?>

1 Answer 1

2

Such a subtle thing. Your are inserting 3 columns (username, hash, cash). The computer thinks you are sending 4 values because of the comma in your cash amount. VALUES(?, ?, 10000,00)

1
  • Great catch! (I'm in the US, where we use a period instead of a comma for decimals.) Sep 18, 2016 at 2:06

You must log in to answer this question.

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