Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Test db value using radio button on a form

Posted on 2006-03-27
4
Medium Priority
?
267 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
0
Comment
Question by:koochy
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Tomeeboy
ID: 16308039
You need to echo 'checked':

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

Author Comment

by:koochy
ID: 16308383
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>


0
 
LVL 1

Accepted Solution

by:
ledave earned 1000 total points
ID: 16310016
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
0
 

Author Comment

by:koochy
ID: 16314345
that did it .. thank you SOOOOOOOO much
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question