0
I’m starting in OO in php, and with the function below I’m trying to check if the name coming from the form is equal to some value coming from my user table before making Insert in the table. I wish someone could shed some light since none of the attempts have worked so far and this is as close as I can get.
public function validarDadosUsuario($validaNome) {
require('conexao.php');
$sql = "SELECT * FROM usuario";
$result = $conn->query($sql);
$dados = $result->fetchAll(PDO::FETCH_ASSOC);
foreach ($dados as $row) {
foreach ($row as $indice => $value) {
if($row[$indice] == $validaNome) {
echo 'Nomes iguais';
$this->$validaNome = true;
break;
} else {
echo 'Nomes diferentes';
$this->validaNome = false;
}
}
}
return $validaNome;
}
$usuario = new Usuario($_POST['add_name'], $_POST['add_email'], $_POST['add_type'], $_POST['add_password']);
$user->validatedUsuario($_POST['add_name']);
only with this data we cannot help
– user148170