
How to create database and Connect it with msqli in VS code?
.html
<!DOCTYPE html>
<htm>
<head>
<titel>Form site</titel>
</head>
<body>
<center>
<form method="post" action="connect.php">
username: <input type="text" name="username"><br><br>
password: <input type="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
</center>
</body>
</htm>
How to create database and Connect it with msqli in VS code?
.PHP
<?php
$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username)){
if (!empty($password)){
$host = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "youtube";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()){
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());
}
else{
$sql = "INSERT INTO account (username, password)
values ('$username','$password')";
if ($conn->query($sql)){
echo "New record is inserted sucessfully";
}
else{
echo "Error: ". $sql ."
". $conn->error;
}
$conn->close();
}
}
else{
echo "Password should not be empty";
die();
}
}
else{
echo "Username should not be empty";
die();
}
?>