0

I am trying to assign a PHP variable to an html radio button value like this:

echo "<input type='radio' name='mydisctopic' value="($row['message'])">",($row['message']),"<br>";

but i keep getting the error:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in ...

Can you help? Thanks!

2
  • In your quest to quote the value of $row['message'] you have ended the string you began to echo, so parse error. By the way, quoting is not enough; you must also use htmlspecialchars on the value. Commented Nov 11, 2013 at 11:21
  • possible duplicate of PHP - concatenate or directly insert variables in string Commented Nov 11, 2013 at 11:46

5 Answers 5

1

Try like

echo "<input type='radio' name='mydisctopic' value='".$row['message']."'>".$row['message']."<br>";
Sign up to request clarification or add additional context in comments.

Comments

0

change the line with

echo "<input type='radio' name='mydisctopic' value='".$row['message']."'>".$row['message']." <br/>";

Comments

0
echo "<input type='radio' name='mydisctopic' value=\"".$row['message']."\">\"".$row['message']."\"<br>";

Better Method:

    <input type="radio" name="mydisctopic" value="<?= $row['message']; ?>">"<?= $row['message']; ?>"<br>";

Comments

0

change to:

echo "<input type='radio' name='mydisctopic' value='". $row['message'] ."'>". $row['message'] ."<br>";

Comments

0

I like to use " for HTML attributes so:

echo '<input type="radio" name="mydisctopic" value="'.$row['message'].'">'.$row['message'].'<br>';

' is faster for interpreter

If you want to use double quotes you can do this:

echo "<input type='radio' name='mydisctopic' value='{$row['message']}'>{$row['message']}<br>";

If you want to use commas (as echo can do this)

echo '<input type="radio" name="mydisctopic" value="',$row['message'],'">',$row['message'],'<br>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.