使用php预填充HTML Radio选择

使用php预填充HTML Radio选择

问题描述:

So based on if my database value is a 1 or 0 I want this enabled/disabled api settings page radio buttons to be prepopulated. Yet everything I have seen online simply is not working. Any ideas how to get this to work? Here is my snippit code on how I am doing my radio portion. Keep in mind when I select enable or disable and submit my form it does change the database value to a 1 or 0. I just can't get it to be selected when the page loads for my life :| ... Any help is appreciated! status is my variable set to a 1 or 0 by the way!

<form action="api_settings.php"  method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
  <tr>
    Status:<br />
    <input type="radio" name="status"  value="0" <?php if($status == 0){?> checked="checked"<?}?> />Disabled Remote Access<br />
    <input type="radio" name="status"  value="1" <?php if($status == 1){?> checked="checked"<?}?> />Enabled Remote Access<br />
  </tr>

I don't believe it's a problem with the PHP, I think the problem is that you don't have a <td></td> tag within your <tr></tr>.

Before: http://jsfiddle.net/efYZF/ After: http://jsfiddle.net/efYZF/1/