Radio buttons - checked based on sql value

I have a form with a radio button on it. It is an edit user form.

I have a radio button for Application type. In the db, it is either 0 for trial or 1 for annual. When I got to edit user, I am trying to figure out how to have the correct radio buttons checked.

<tr>
<td class="label"><?php echo $ML_LABELS['app_type'];?></td>
<td>
<input type="radio" name="app_type" id="app_type" value="<?php echo readFromDB($user['app_type']);?>" size="50" /> Trial 
<input type="radio" name="app_type" id="app_type" value="<?php echo readFromDB($user['app_type']);?>" size="50" /> Annual </td>
</tr>

I cant figure out how to do this. I tried if statement, but maybe i didnt do it right. Can someone please help me. Thank you

[php]

<?php $selected_radio = $_POST['app_type']; $row = mysql_fetch_assoc($result); ?>

<input type=“radio” name=“app_type” value=“red” <?php if ($row['app_type'] == "1"){echo "checked";} ;?>/>Red
<input type=“radio” name=“app_type” value=“Green” <?php if ($row['app_type'] == "1"){echo "checked";} ;?>/>Green
<input type=“radio” name=“app_type” value=“Black” <?php if ($row['app_type'] == "1"){echo "checked";} ;?>/>Black
<input type=“radio” name=“app_type” value=“White” <?php if ($row['app_type'] == "1"){echo "checked";} ;?> />White[/php]

It doesnt seem to be working. Neither radio button is checked.

			<?php
			$selected_radio = $_POST['app_type'];
			$row = mysql_fetch_assoc($result);
			?>
			<tr>
			<td class="label"><?php echo $ML_LABELS['app_type'];?></td>
				<td>
				<input type="radio" name="app_type" value="0" <?php if ($row['app_type'] == "0"){echo "checked";} ;?>/>Trial  
				<input type="radio" name="app_type" value="1" <?php if ($row['app_type'] == "1"){echo "checked";} ;?>/>Anual  
				</td>
			</tr>

what do you mean is not workin? what does it do

nothing

there are two options, trial and annual. in the db trial is stored as 0 and annual is stored as 1

<?php $selected_radio = $_POST['app_type']; $row = mysql_fetch_assoc($result); ?>

where is $selected_radio used?

So this is where I am at. No matter what is in the db 0 or 1, annual is always checked.

			<?php
				$app_trial = "unchecked";
				$app_annual = "unchecked";
					$selected_radio = $_POST['app_type'];
						if ($selected_radio == '0') {
							$app_trial = "checked";
						}
						else if ($selected_radio == '1') {
							$app_annual = "checked";
						}
			?>
			
			<tr>
			<td class="label"><?php echo $ML_LABELS['app_type'];?></td>
				<td>
					<input type="radio" name ="app_type"  value= "0" checked=<?php print $app_trial; ?> size="50" /> Trial  
					<input type="radio" name ="app_type"  value= "1" checked=<?php print $app_annual; ?> size="50" /> Annual    
				</td>
			</tr>

$selected_radio = $_POST[‘app_type’]; is just an example

everything os from the database.

no matter what i do, annual is always checked. If i do text instead, i can see it changing from checked to unchecked, etc. But it doesnt with a radio button. What am I doing wrong.

think maybe i got it

if it still not working, i can help you directly using teamviewer.

Sponsor our Newsletter | Privacy Policy | Terms of Service