Link to home
Start Free TrialLog in
Avatar of koochy
koochyFlag for United States of America

asked on

Test db value using radio button on a form

I have a form that pulls the value from the 'approved' field in my db ... but I prefer to use a rdio button ... how do I test for the value in the table in order to populate the correct radio button ..

here is the code I attempted:

echo "<td>Yes&nbsp;</td>\n";
echo "<input <?php if ($row['approved'] == 'Yes') {'checked'; } ?> type='radio' name='approved' value='Yes'>&nbsp;No&nbsp;<input <?php if ($row['approved'] == 'No') {'checked; } ?> type="radio" name='approved' value='No'></td>\n";

the error message i get is this:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\options\websites\foalauctiontest\admin\edit_seller.php on line 164

I'm tretty new to php but I understand asp forms and radio buttons .. any help would be greatly appreciated ...

TIA
Avatar of Tomeeboy
Tomeeboy
Flag of United States of America image

You need to echo 'checked':

<?php if ($row['approved'] == 'Yes') { echo 'checked'; } ?>
Avatar of koochy

ASKER

that didn't work .. here is the entire form ...

<form action="edit_seller.php?ID=<?php echo $row['sellerID'] ?>" method="post">
<?php
echo "<table cellpadding='5' cellspacing='0' border='0'>";
echo "<tr>\n";
echo "<td>Seller ID:</td>\n";
echo "<td>" . $row['sellerID'] . "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>First Name:</td>\n";
echo "<td><input type='text' name='first_name' value='" . $row['first_name'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Last Name:</td>\n";
echo "<td><input type='text' name='last_name' value='" . $row['last_name'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Company:</td>\n";
echo "<td><input type='text' name='company_farm' value='";
echo $farmname;
echo "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Street Address:</td>\n";
echo "<td><input type='text' name='address' value='" . $row['address'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>City or Town: </td>\n";
echo "<td><input type='text' name='city' value='" . $row['city'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Province or State:</td>\n";
echo "<td><input type='text' name='province' value='" . $row['province'] . "'></td>\n";
echo "</tr>\n";
echo "<tr> \n";
echo "<td>Postal or Zip Code:</td>\n";
echo "<td><input type='text' name='postal_code' value='" . $row['postal_code'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Country:</td>\n";
echo "<td><input type='text' name='country' value='" . $row['country'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Home Phone Number:</td>\n";
echo "<td><input type='text' name='home_phone' value='" . $row['home_phone'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Work Phone Number:</td>";
echo "<td><input type='text' name='work_phone' value='" . $row['work_phone'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Cell Phone Number:</td>";
echo "<td><input type='text' name='cell_phone' value='" . $row['cell_phone'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Fax Number:</td>";
echo "<td><input type='text' name='fax' value='" . $row['fax'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Email:</td>\n";
echo "<td><input type='text' name='email' value='" . $row['email'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Password:</td>\n";
echo "<td><input type='text' name='password' value='" . $row['password'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Secret Word:</td>\n";
echo "<td><input type='text' name='secret_word' value='" . $row['secret_word'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Website:</td>\n";
echo "<td><input type='text' name='website' value='" . $row['website'] . "'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Approved: </td>\n";
echo "<td>Yes&nbsp;</td><td>\n";
echo "<input <?php if ($row['approved'] == 'Yes') {echo 'checked'; } ?> type='radio' name='approved' value='Yes'>&nbsp;No&nbsp;<input <?php if ($row['approved'] == 'No') {echo 'checked'; } ?> type='radio' name='approved' value='No'></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan='2' align='right'><input type='submit' name='submit' value='Update'></td>\n";
echo "</tr>\n";
echo "</table>\n";
?>
</form>


ASKER CERTIFIED SOLUTION
Avatar of ledave
ledave

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of koochy

ASKER

that did it .. thank you SOOOOOOOO much