This question already has an answer here:
I've been trying to learn php but I got stuck at this basic thing. I really don't know what's wrong. Can u guys look at the code and tell me what's wrong? Thanks.
<?php
session_start();
$connection = mysqli_connect('127.0.0.1', 'root', 'root', 'blogdb');
if(!$connection)
die('error');
$call = '';
$username = $_POST['nickname'];
$password = $_POST['password'];
$password_again = $_POST['password_again'];
if($_POST)
{
if($password != $password_again)
$call = 'Hesla nesouhlasí!';
else if($_POST['year'] != date('Y'))
$call = 'Špatně vyplněný antispam!';
else
{
$exists = mysqli_query('SELECT COUNT(*)
FROM uzivatel
WHERE jmeno=?
LIMIT 1', $username);
if($exists)
$call = 'Uživatelské jméno je obsazeno!';
else
{
mysqli_query("INSERT INTO uzivatel (jmeno , heslo)
VALUES ($username , $password)");
$call = 'Registrace proběhla úspěšně!';
}
}
}
?>
Oh my god, I realized it now. I didn't tell you what was the problem. So the problem was that I couldn't connect to my database. I created new file.php and new DB just to test if I'm doin it right.
$test = mysqli_query($connection ,"INSERT INTO test (jmeno , prijmeni)
VALUES ('test' , 'test')");
This was working so I modified the code but it still doesn't work.
mysqli_query($connection, "INSERT INTO uzivatel (jmeno , heslo)
VALUES ('admin' , 'admin')");
It wont't appear in the DB.
</div>