I am trying to build a connection to a database in 000webhost I have created and just send sample data, but I keep failing. (the idea is to build a form and submit data. Could you please advice based on my code and the database properties what am I missing. I am new to PHP, js, etc.
I have tried to change the localhost and get rid of my password. I have created an HTML with just a submit button and PHP file that gets used in HTML. I have also set up a dummy user table
--HTML file--
<form method="post" action="action_page.php">
<input type="submit">
</form>
action_page.php file
<?php
$servername = "localhost:3306";
$username = "ac8";
$password = "12345";
$dbname = "id10859778_progress";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO user ( f_name, l_name)
VALUES ('John', 'Doe')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
database
https://www.000webhost.com/members/website/slinkier-shelf/database
Server: localhost:3306 »Database: id10859778_progress »Table: user