Hi, I hope I can get the answer that I need here.
So, I’m making a very simple HTML form that can input just a username and a password. I have created a database with 2 collumns for both field, username & password. I have also created both the HTML file and the PHP file. It has a submit button, but when I click on it, it won’t input anything to the database. Instead I get the error message as shown below.
This is my HTML page code:
<!DOCTYPE html>
<html>
<head>
<title>Form site</title>
</head>
<body>
<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>
</body>
</html>
This is my PHP script:
<?php
$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
if (!empty($username)){
if (!empty($password)){
$host = "sql306.epizy.com";
$dbusername = "epiz_31851316";
$dbpassword = "PASSWORDHERE";
$dbname = "epiz_31851316_youtube";
// Create connection
$conn = new mysqli ($sql306.epizy.com, $epiz_31851316, $PASSWORDHERE, $epiz_31851316_youtube);
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();
}
?>
How do I connect the database with the HTML form? Where do I input my host name, database name, username and password in the PHP script?
The host, database name, username and password are all supposedly correct, just as provided on the MySQL Details and home vp page.
### Username
epiz_31851316
### Error Message
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(); } ?>
### Other Information
Any input/help would be much appreciated. Thank you.