0
votes

I have this problem. I am trying to connect to a database and push a text user. When I open the file I just get lots of errors. You can see the errors and my code further down. FYI: my database is in MySQLi

Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in /www/webvol9/rj/fxgnq6r66hz6x2j/my domain/public_html/action_page.php on line 3

Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in /www/webvol9/rj/fxgnq6r66hz6x2j/my domain/public_html/action_page.php on line 3

Notice: Undefined variable: query in /www/webvol9/rj/fxgnq6r66hz6x2j/my domain/public_html/action_page.php on line 7

Warning: mysqli::prepare(): Couldn't fetch mysqli in /www/webvol9/rj/fxgnq6r66hz6x2j/my domain/public_html/action_page.php on line 7

Fatal error: Uncaught Error: Call to a member function execute() on null in /www/webvol9/rj/fxgnq6r66hz6x2j/my domain/public_html/action_page.php:8 Stack trace: #0 {main} thrown in /www/webvol9/rj/fxgnq6r66hz6x2j/my domain/public_html/action_page.php on line 8

<?php
// Create connection
$mysqli = new mysqli("https://mysql687.loopia.se", "USERNAME", "PASSWORD", "People");

$query = "INSERT INTO 'People' ('Name', 'Password', 'Username') VALUES ('Emil', 'hejhej', 'emil')";

$stmt = $mysqli->prepare($query);
$stmt->execute();

$mysqli->close();
$stmt->close();
?>
2
write $query instead of $querry - Bhargav Chudasama
use this syntax mysqli('localhost', 'my_user', 'my_password', 'my_db'); - Bhargav Chudasama
Remove https from your host address and fixed a typo in your $query variable name. Write $query instead of $querry - Igor Ilic
Don't include real conneciton strings or keys in your code. Stack Overflow is public! - Dragonthoughts

2 Answers

0
votes

There are a lot of bugs here

Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in ...

Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: hostname nor servname provided, or not known in ...

Are because you connect with the database through port 443 when you put https:// in front of the domain.

Just did a port scanner and port 443 is closed, the default mySQL port 3306 is open so just enter mysql687.loopia.se without the https://

port 3306 port 443

Notice: Undefined variable: query in ...

Replace single quotes for table columns to backticks or none:

$query = "INSERT INTO `People` (`Name`, `Password`, `Username`) VALUES ('Emil', 'hejhej', 'emil')";

Also close statement before database connection (also only close the database connection when its the end of the script. Not every time you run a query).

$stmt = null;
$mysqli = null;
0
votes

First connect with proper credentials to your database. Don't quote table name and column names in

$query = "INSERT INTO People (Name, Password, Username) VALUES ('Emil', 'hejhej', 'emil')";

$stmt->close(); should come before $mysqli->close();.