We help IT Professionals succeed at work.

Test db value using radio button on a form

koochy
koochy asked
on
Medium Priority
280 Views
Last Modified: 2008-03-17
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
Comment
Watch Question

CERTIFIED EXPERT

Commented:
You need to echo 'checked':

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

Author

Commented:
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>


Commented:
hi there,
you don't have to re-start the php again. I explain, you're already into php and in your echo you start another one.
Try this:
if ($row['approved'] == 'Yes'){
echo "<input type='radio' name='approved' value='Yes' checked>&nbsp;No&nbsp;<input type='radio' name='approved' value='No'></td>\n";
}else{
echo "<input type='radio' name='approved' value='Yes'>&nbsp;No&nbsp;<input type='radio' name='approved' value='No' checked ></td>\n";
}

instead of:
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";

hope it helps
ledave

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
that did it .. thank you SOOOOOOOO much
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.