Srikumar
Srikumar

Reputation: 1

radio button in php

I retrieved the value from database and I want to print it in radio button as given below.

<input type="radio" value="<?php $row['Username']; ?>" name="myradiobutton" />

While storing the 'Username' in the attribute - "value", it's not working. Can any one please clarify my doubt.

Upvotes: 0

Views: 229

Answers (3)

Michael Berkowski
Michael Berkowski

Reputation: 270599

You need to output the value with echo. Also escape it with htmlentities() as suggested in Fabio M's comment.

<input type="radio" value="<?php echo htmlentities($row['Username'], ENT_QUOTES); ?>" name="myradiobutton" />
                                ^^^^^^

Upvotes: 4

RJD22
RJD22

Reputation: 10340

For the ones that want to know there is also a short tag for this:

<input type="radio" value="<?=$row['Username']?>" name="myradiobutton" />

Upvotes: 1

AJ.
AJ.

Reputation: 28174

Just add echo:

value="<?php echo $row['Username']; ?>"

Upvotes: 2

Related Questions