Israel

Israel

  • NA
  • 1.3k
  • 204.5k

How can I separate these conditions

Dec 21 2022 2:19 AM

Hi,

I have five inputs texts with another one where the right answer stay just there.

See the example: What is the capital of india?

1. Hyderabad

2. Bangalore

3. Delhi

4. Chennai

5. Pune

6. Right answer: Delhi

On click on a specific number as button. It will checks and compares wich number is the same with the six one. If it's the same will show the message 'right'. Otherwise will show the the message 'not true'.

Unfortunatly when I click its shows the two messages at once 'right' and 'not true'. Then how can I separate. Means its should show only the one answer (right) or (not true).

<?php
if(isset($_POST['1'], $_POST['6'])){
    echo $_POST['1'] === $_POST['6'] ? '<input type="text" style="background: green; color: white" value="Right">' : '<input type="text" style="background: red; color: white" value="Not true">';
if(isset($_POST['2'], $_POST['6'])){
    echo $_POST['2'] === $_POST['6'] ? '<input type="text" style="background: green; color: white" value="Right">' : '<input type="text" style="background: red; color: white" value="Not true">';    

if(isset($_POST['3'], $_POST['6'])){
    echo $_POST['3'] === $_POST['6'] ? '<input type="text" style="background: green; color: white" value="Right">' : '<input type="text" style="background: red; color: white" value="Not true">';
}
if(isset($_POST['4'], $_POST['6'])){
    echo $_POST['4'] === $_POST['6'] ? '<input type="text" style="background: green; color: white" value="Right">' : '<input type="text" style="background: red; color: white" value="Not true">';
}    

if(isset($_POST['5'], $_POST['6'])){
    echo $_POST['5'] === $_POST['6'] ? '<input type="text" style="background: green; color: white" value="Right">' : '<input type="text" style="background: red; color: white" value="Not true">';
}   
    
}
}
?>

<form action="" method="post">
    <input type="text" name='1' placeholder='File 1'>
    <input type="text" name='2' placeholder='File 2'>
    <input type="text" name='3' placeholder='File 3'>
    <input type="text" name='4' placeholder='File 4'>
    <input type="text" name='5' placeholder='File 5'>
    <input type="text" name='6' placeholder='File 6'>
    <input type='submit' value='GO!'>
</form>

 


Answers (1)