0

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();
?>
4
  • write $query instead of $querry Commented Jul 17, 2018 at 13:08
  • use this syntax mysqli('localhost', 'my_user', 'my_password', 'my_db'); Commented Jul 17, 2018 at 13:11
  • 2
    Remove https from your host address and fixed a typo in your $query variable name. Write $query instead of $querry Commented Jul 17, 2018 at 13:12
  • Don't include real conneciton strings or keys in your code. Stack Overflow is public! Commented Jul 17, 2018 at 13:14

2 Answers 2

0

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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();.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.