php - register including post fail

632

I am trying to build a login system with registration etc. now for the registration i use a form and the method "post". Now it fails in what i think is sending the input trough the post. can you help me fix it? here is the code involved in it:

above !doctype

<?php
include('connect.php');
// If the values are posted, insert them into the database.
if (isset($_POST["username"]) && isset($_POST["password"])){
    $username = $_POST["username"];
    $email = $_POST["email"];
    $password = $_POST["password"];

    $query = "INSERT INTO `user` (username, password, email) VALUES ($username, $password, $email)";
    $result = mysqli_query($query);
    if($result){
        $msg = "User Created Successfully.";
    }
else
  {echo "fail";}
}
?>

the form:

<div class="register-form">
<?php
if(isset($msg) & !empty($msg)){
    echo $msg;
}
?>
<h1>Registreer</h1>
<form action="" method="POST">
<p><label>User Name : </label>
<input id="username" type="text" name="username" placeholder="username" /></p>

<p><label>E-Mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : </label>
 <input id="password" type="email" name="email" required placeholder="[email protected]" /></p>

 <p><label>Password&nbsp;&nbsp; : </label>
 <input id="password" type="password" name="password" placeholder="password" /></p>

<a href="login.php">Login</a>
<input type="submit" name="submit" value="Registreer" />
</form>

</div>  

The connect.php

<?php
$servername = "localhost";
$username = "sqluser";
$password = "Welkom01!";
$dbname = "users";

$connection = mysqli_connect($servername, $username, $password);
if (!$connection){
die("Database Connection Failed". mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, $dbname);
if (!$select_db){
die("Database Selection Failed" . mysqli_error($connection));
}
?>

Thanks in advance.

People are also looking for solutions to the problem: php - Return a variable from a function to a view

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.