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"];
}
}
}
?>