0

I am getting value from sql db and making option by setting Radio for unique values. For this reason i am placing value = '<?php $row[' ']..... ;?>' but i am getting error every time. Looks like i am not doing correctly passing php in value bcz when i remove then everything gets fine. Any one can guide please.

Code:

        while($row = mysql_fetch_array($query) or die(mysql_error())){

        echo '<form>';
            while ($row=mysql_fetch_array($query))
            {


                echo '<div class="boxed" >';

                echo "\t".'<tr><th>'.$row['question']."<br>".'</th><th>'."<input type='radio' name='optn' value=' <?php $row['A']; ?> '>".$row['A']."<br>".'</th><th>'."<input type='radio' name='optn' value='<?php $row['B']; ?>'>".$row['B']."<br>".'</th><th>'."<input type='radio' name='optn' value='<?php $row['C']; ?>'>".$row['C']."<br>".'</th><th>'."<input type='radio' name='optn' value='<?php $row['D']; ?>'>".$row['D'].'</th></tr>';
            //  echo '<tr><th>'.'<font size="5" color=#07c >'."<a href='reply.php?name=$id'>".$row['qtitle']."</a>".'</font>'.'</th><th>'."&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;".'<font size="2" color=#07c >'.$row['Date']."&ensp;&ensp;&ensp;".$row['Time']."<br>".'</font>'.'</th><th>'.$row['askquestion'].'</th></tr>';
            //  echo"<th> <a href ='delete.php?name=$id'><center>Delete</center></a></th></tr>";
                echo '<input type="submit" name="submit" />';

                echo '</div>';
            }
        echo '</form>';
        }

Error:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\New folder\htdocs\website\Quizes.php on line 245
user3440716
  • 599
  • 2
  • 10
  • 22

2 Answers2

1

The way in which you were embedding the php tags within the quoted string was causing the issue. You will find it easier to format the code properly IMO! I think the following ought to be ok, the values are now encapsulated in curly braces.

    while($row = mysql_fetch_array($query) or die(mysql_error())){

    echo '<form>';
        while ($row=mysql_fetch_array($query))
        {


            echo '<div class="boxed" >';

            echo "\t".'<tr><th>'.
            $row['question']."<br>".
            '</th><th>'."<input type='radio' name='optn' value='{$row['A']}'>".$row['A']."<br>".
            '</th><th>'."<input type='radio' name='optn' value='{$row['B']}'>".$row['B']."<br>".
            '</th><th>'."<input type='radio' name='optn' value='{$row['C']}'>".$row['C']."<br>".
            '</th><th>'."<input type='radio' name='optn' value='{$row['D']}'>".$row['D'].'</th>
            </tr>';
            echo '<input type="submit" name="submit" />';

            echo '</div>';
        }
    echo '</form>';
    }

Below is a re-written version which, I think, better illustrates the problems in the code you gave.

while( $row = mysql_fetch_array($query) or die(mysql_error())){
echo '<form>';
    while( $row=mysql_fetch_array( $query ) ){
        echo "
        <div class='boxed'>
            <tr>
                <th>
                    {$row['question']}<br>
                </th>
                <th><input type='radio' name='optn' value='{$row['A']}'>{$row['A']}<br>
                </th><th><input type='radio' name='optn' value='{$row['B']}'>{$row['B']}<br>
                </th><th><input type='radio' name='optn' value='{$row['C']}'>{$row['C']}<br>
                </th><th><input type='radio' name='optn' value='{$row['D']}'>{$row['D']}</th>
            </tr>
            <input type='submit' name='submit' />
        </div>";
    }
echo "</form>";
}

There is no table tag yet you have tr and th tags and there is a nested while loop...

Professor Abronsius
  • 26,348
  • 5
  • 26
  • 38
1

Parse error due to this:

<?php $row['A']; ?>

You are using it in the php script you can use it as

". $row['A'] . "
devpro
  • 15,966
  • 3
  • 25
  • 38