-1

I'm currently trying to make a login system and it all works in xampp but when I upload it and connect it to my hosted database it just gives me an error.

error is:

PHP Fatal error: Uncaught Error: Call to undefined method mysqli::error() in /path/to/public/gnpfonline/Beta/register.php:19

On line 19 is $result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error());. I don't quite see whats wrong as it works fine in xampp but not on the hosted SQL database, I have tried 2 different sites for this and they both do not work.

Tom
  • 3,031
  • 1
  • 25
  • 33
  • The method `mysqli::error()` is not defined. That can differ between hosts as the PHP configuration can differ between hosts and some hosts might just not have PHP provide that method. Please contact your hosts technical support and tell them what your requirements for your PHP application are (e.g. that method). – hakre Apr 14 '18 at 20:08
  • Alternatively it can also be that this method never exists, but only on some hosts that part of your code is executed. That is at least what a [similar Q&A here on SO suggests](https://stackoverflow.com/q/11945912/367456). – hakre Apr 14 '18 at 20:10

2 Answers2

4

Your problem is that there is no such function as error() in mysqli. Your code should be:

$result = $mysqli->query("SELECT * FROM users WHERE email='$email'") or die($mysqli->error);

...which accesses the error property (a string) of your $mysqli object. It's not a function.

The reason it's failing in your hosted database is because you're actually getting an error when you try to run your query. If you fix the error-displaying code, you should see the real error.

(You have the bug in your error handling both locally and on your remote machine; it's just that PHP never runs your error-handling code locally because there's no error from $mysqli->query() locally. It's only failing on the remote server.)

Typical reasons for errors after deploying to a different host are things like having the wrong database connection configuration for your hosted database. You'll get more information when you fix the error-checking code.

Matt Gibson
  • 37,886
  • 9
  • 99
  • 128
2

The mysqli-error is not a function.

printf("Errormessage: %s\n", $mysqli->error);
Gelor
  • 21
  • 2