0

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
Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49
  • 1
    you'll prolly need to turn on error reporting and check out error logs, "not working" or "white screen" won't get us really that far – Kevin Sep 17 '19 at 04:43
  • See: https://stackoverflow.com/questions/15318368/mysqli-or-die-does-it-have-to-die – Dharman Sep 17 '19 at 09:00

2 Answers2

0

Your form is missing an action bit.

<Form method=post action=action_page.php>
Shane Weeks
  • 77
  • 1
  • 4
0

this link was helpful: https://www.000webhost.com/forum/t/sqlstate-hy000-1045-proxysql-error-access-denied-for-user/48044/8

issue was with my variables, i got rid of :3306 and also updated my username to the one created automatically.