vendredi 15 juillet 2016

Call to a member function query() on null - PHP

Here is code:

$connect = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if($connect->connect_errno) {
   printf("Connect failed: %sn", $connect->connect_error);
   exit();
}

function send($username="", $password="") {
    $connect->query("INSERT INTO table1 (username, password) VALUES ('$username', '$password')");
 }
$connect->close();

Notice: Undefined variable: connect in C:xampphtdocsplayground01buildcomponentsincludesroot.php on line 44

Fatal error: Call to a member function query() on null in C:xampphtdocsplayground01buildcomponentsincludesroot.php on line 44

Where is a problem?

Aucun commentaire:

Enregistrer un commentaire