如何根据单选按钮选择更改表单提交页面上的文本? [重复]

如何根据单选按钮选择更改表单提交页面上的文本?  [重复]

问题描述:

This question already has an answer here:

On "form.html", I have a basic HTML form:

<form method="post" action="submit.php">
  <input type="radio" name="SQ1" value="y"> Yes<br>
  <input type="radio" name="SQ1" value="n"> No<br>
  <input type="submit">
</form>

On "submit.php", I have a table. I am trying to change the text inside the table based on what radio button is selected.

<table id="results">
    <tr>
        <th>h1</th>
        <th>h2</th>
        <th>h3</th>
        <th>h4</th>
        <th>h5</th>
        <th>h6</th>
    </tr>
    <tr>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "0";
            }
            else {
                echo "1";
            }
        ?></td>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "0";
            }
            else {
                echo "1";
            }
        ?></td>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
        <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
                <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
                <td><?php
            $sq1 = $_POST["sq1"];
            if ($sq1 = y) {
                echo "1";
            }
            else {
                echo "0";
            }
        ?></td>
    </tr>
</table>

No matter what button is selected, the data appears as if $sq1 = y.

</div>

You have problem with your if statement condition, 1) if($sq1=y) will return true it is assignment operation

2) y is string use the double quotation "y".

3) to compare string use == or strcmp($var1,$var2) which returns 0 in case of equal strings