-2
I’m trying to make an if structure that depends on the number of content in an array and apparently is counting wrong, because regardless of how much content I select it redirects me to the page I asked for in one condition:
else if(isset($_POST['alterar'])){
foreach ($_POST['selecionado'] as $cpf){
$sql = "SELECT * FROM tbl_usuario WHERE cpf = '$cpf'";
$result = mysqli_query($strcon,$sql) or die("<script type='text/javascript'>alert('Erro no acesso aos dados');</script>");
$linhas[] += $result;
}
if(count($linhas) == 1){
echo "<script type='text/javascript'>window.location='cadastro.php';</script>";
}
else{
echo "<script type='text/javascript'>alert('Escolha uma linha apenas');</script>";
}
}
always falls in Is? ever tried to give a
var_dump($linhas)
?– rray
falls in if ever, which would be a var_dump ?
– Caio Vieira
When you do
$array[] = 'alguma coisa';
it adds a new element. It seems that themysqli_fetch()
– rray
the problem is that in mysqli_fetch you can not do $lines += mysqli_fetch_array($result), so it will always create a new $lines and not add more lines in the same array, the structure is a foreach... I tried with fetch and it did not give mt right
– Caio Vieira
What do you want your code to do? more than one Cpf can be sent?
– rray
No, exactly the opposite first it counts how many cpfs are being selected, if it is more than one or 0 he of the error if it is only 1 it passes to another window in which I will put the data referring to this Cpf inside some textbox
– Caio Vieira