0
I’m in trouble, look at the code I made:
<?php
class banco {
public function __construct() {
$banco_hostremoto = "127.0.0.1";
$banco_hostname = "localhost";
$banco_usuario="root";
$banco_passwd="";
$banco_nome="flptrevisan";
$conn = mysql_connect($banco_hostname,$banco_usuario,$banco_passwd);
if (!mysql_ping($conn)) { $FORADOAR = TRUE; }
else if (mysql_ping($conn)) {
$FORADOAR = FALSE;
$conexao = new mysqli($banco_hostname,$banco_usuario,$banco_passwd,$banco_nome);
}
}
public function signIn($email,$senha) {
$this->conexao->query("SELECT * FROM usuarios WHERE email = '$email' AND senha = '$senha'");
if ($sql->num_rows==1){
while($linha = $sql->fetch_array()) {
$usuario = $linha['nome'];
$acessos = $linha['acessos']+1;
}
$ip=$_SERVER["REMOTE_ADDR"];
$sql = $conexao->prepare("UPDATE usuarios SET acessos = ?, ip = ? WHERE email = ?");
$sql->bind_param('iss',$acessos,$ip,$email);
$sql->execute();
$_SESSION["autenticado"]=$email;
$_SESSION["usuario"]=$usuario;
header('location:index.php');
}
else {
echo '<div class="alertaIndexMSG">O usuário ou senha inserido é inválido(a)</div>';
}
}
}
From the following error:
Notice: Undefined Property: bank::$connectionin C: htdocs Netbeansprojects flptrevisan classes conexao.class.php on line 20
Fatal error: Call to a Member Function query() on a non-object in C: htdocs Netbeansprojects flptrevisan classes conexao.class.php on line 20
Line 20 is:
$this->connection->query("SELECT * FROM users WHERE email = '$email' AND password = '$password'");
Hello, I made the change but still giving error: Fatal error: Call to a Member Function query() on a non-object in C: htdocs Netbeansprojects flptrevisan classes connected to.class.php on line 13 Line 13: $this->connected->query("SELECT * FROM usuarios WHERE email = '$email' AND password = '$password'"); New complete code: http://pastebin.com/uJjR2WEK
– Barack
Remember to do the assignment correctly, here you are adding to a local variable
$conexao = new mysqli(...)
change to:$this->conexao = new mysqli(...)
– rray
Deu, went through that error but now comes this: Notice: Undefined variable: sql in C: htdocs Netbeansprojects flptrevisan classes conexao.class.php on line 14 Notice: Trying to get Property of non-Object in C: htdocs Netbeansprojects flptrevisan classes connected.class.php on line 14 The user or password entered is invalid(a)
– Barack
The return of the consultation(
$this->conexao->query()
) needs to be assigned to a variable in the case$sql
.– rray
Thanks now this working out
– Barack
Now I’m adjusting the code in the structure I want and again gave error. Look, are two files one with each class. , the class of the connection and the class of the Autenticacao, I want to inherit in the Autenticacao the Construct of the opening of the connection. File of the Autenticacao class: http://pastebin.com/a7mfxSjU File of the connected class: http://pastebin.com/FmfCWDRC The error is: Fatal error: Call to a Member Function query() on a non-object in C:htdocs Netbeansprojects flptrevisan classes Autenticacao.class.php on line 8 Always on that line that calls the connection
– Barack
I got the private out of the public connection!
– Barack