Condition that check the registration

Asked

Viewed 35 times

0

I have to create a condition to verify the entry of a record. In that insertion I have dois inputs type radio, one with value="Ok" and another with value="Não Ok":

$tabela1 .= '<td style="float:center"> <input type="radio" name= "Sim['.$y.']" value="Ok" required></td>';
$tabela1 .= '<td style="float:center"> <input type="radio" name= "Sim['.$y.']" value="Não Ok" required></td>';

When I enter the record in the database table, it inserts 23 lines. By inserting the 23 lines I want to create a if check if it exists in one of the rows when inserting with value="Não Ok" then the condition is true, if on the 23 lines you receive the value="Ok" then the condition is false.

I’m doing it this way but it’s not working:

if($sim != "Ok"){
....
}else{
....
}

This way, receive in all 23 lines value="Ok" or in one or more lines receive the value="Não Ok" the condition is always false.

1 answer

1


Before in your HTML the name this one with capital S and in php is minuscule, I don’t know if you have any problem, but it’s good to leave the two equal.

$tabela1 .= '<td style="float:center"> <input type="radio" name= "sim['.$y.']" value="Ok" required></td>';

In PHP check if any of the inputs is marked "Not OK", if you are setting a variable just to check this, and then check on top of that variable.

$res = false;
if($Sim == "Não Ok"){
    $res = true;
}

In the next if:

if($res){
    //Não OK
}else{
    //OK
}
  • so much put if(in_array("OK", $sim)){ or if(in_array("Não OK", $sim)){ always sends what is inside the else

  • Utilize being case sensitive, I just realized that no value this Ok and if this OK, I’ll edit the question.

  • I am making the if condition after closing the forto send everything only in one email, because if it is inside the forsends an email by line. That’s why you can’t check the array

  • Dude, without seeing the full code gets kind of hard, but your array $sim is receiving in HTML a variable (I imagine it to be counter) inside the brackets, so you need to check the structure of your array, because if the variable $i is printing 1 for example, in if you would use in_array("Ok", $sim[1])

  • we can continue to chat?

  • We can, but instead I suggest you edit your question with the full code and value of the array (use a var_dump($sim)) so other people can help too.

  • I posted but then I deleted it because it gets too much code the question and is not well received by the community

  • when I do var_dump($sim) outside the for return this string(2) "Ok" and not the value of the 23 lines, but if done within the foralready returns the 23 lines, the problem is doing the if outside the for

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.