I've created a simple MySQL connection to insert data. The connection is fine, but when I submit the form data, the INSERT
is not working. But if I put manual data into the query, it works fine.
<form action="dbconnection.php" method="POST">
<label>Username</label>
<input type="text" name="username" placeholder="Username" required=""/>
<label>Password</label>
<input type="text" name="password" required="" placeholder="Password"/>
<input type="submit" value="save"/>
</form>
<?php
print_r($_POST);
$server = "localhost";
$dbname="mytestdb";
$username = "root";
$password= "";
//create connection
$conn = mysqli_connect($server,$username,$password,$dbname);
//check connection
if($conn->connect_error){
die("connection failed". $conn->connect_error);
}
echo "connected successfull";
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "INSERT INTO user('username','password') VALUES ($username,$password)";
mysqli_query($conn,$sql);