-4
I have my file php connection. with the code below:
$banco_hostname = "localhost";
$banco_usuario="root";
$banco_passwd="";
$banco_nome="banquinho";
$conexao = new mysqli($banco_hostname,$banco_usuario,$banco_passwd,$banco_nome);
There in my file banco.oo.php with the classes (object oriented) I have:
class autenticacao {
    function SignUp($conexao,$nome_post,$email_post,$passwd_post,$k_post,$k) {
        if( (!$nome_post) || (!$email_post) || (!$passwd_post) || (!$k_post) || ($k_post != $k) ){
            header('location:index.php');
        }
        else{
                // VERIFICA SE USUARIO OU EMAIL EXISTE CADASTRADO
                $sql = $conexao->query("SELECT email FROM usuarios WHERE email='$email_post'");
                if ($sql->num_rows==1){
                    echo '<div class="alertaIndexMSG">Ocorreu um erro, este e-mail ja possui um cadastro no banco de dados...</div>';
                }
                else {
                    $acessos=1;
                    $ip=$_SERVER["REMOTE_ADDR"];
                    // INSERE USUARIO AO BANCO DE DADOS
                    $sql = $conexao->prepare("INSERT usuarios SET nome = ?, email = ?, passwd = ?, ip = ?, acessos = ?");
                    $sql->bind_param('ssssi',$nome_post,$email_post,$passwd_post,$ip,$acessos);
                    $sql->execute();
                    $_SESSION["message-signup"]=TRUE;
                    $_SESSION["autenticado"]=$email_post;
                    $_SESSION["usuario"]=$nome_post;
                    header('location:index.php');
                }
        }
    }
}
There in my file index php. i would have a form for Signup as an example
<html>
<head>
<meta charset="UTF-8">
<title>Titulo</title>
</head>
<body>
 <!-- FORMULARIO DE SIGN UP AQUI -->
</body>
</html>
There in my file that processes the Signup form I have:
include("conexao.php");
include("banco.oo.php");
if (isset($_POST["signin"])){
    $email=$_POST["email"];
    $passwd=md5($_POST["passwd"]);
    $OO = new autenticacao();
    $OO -> SignIn($conexao,$email,$passwd);
}
So let’s have my question/problem:
I remember that before I didn’t need to take the variable $connected always in all $OO -> Signin($connected,$email,$passwd); because the same one was already pulling inside the file bank.oo.php when starting the class I think that as inheritance of the class all functions of it ended up receiving this variable that makes connect to the bank when calling the class, but now I don’t know what I did wrong in the database.oo.php that every time I call a function I have to leave taking this variable and getting it there in the function to connect to the bank.
What my mistake in object orientation I made?
There is no OOP in this code. Separating into classes does not mean OO - besides, you will have trouble passing
$conexao– Papa Charlie