Solved

input type=radio question

Posted on 2001-08-04
3
226 Views
Last Modified: 2006-11-17
Hello

I have a field in my table that is called "template" and i have a form with 3 radio buttons.

When the form is loaded it has to check a radio button depending on the value.
When i submit the form it has to write the value into my table field "template".

The code i try to use looks like:

echo "<input type=radio value=1 name=template ".if ($row[template]==1) echo "checked".">";
echo "<input type=radio value=2 name=template ".if ($row[template]==2) echo "checked".">";
echo "<input type=radio value=3 name=template ".if ($row[template]==3) echo "checked".">";

Why does this not work:

I always get a parse error
0
Comment
Question by:volvo
  • 2
3 Comments
 

Expert Comment

by:cynicz
ID: 6351968
change that to
echo "<input type=radio value=1 name=template" . ($row[template]==1) ? " checked" : "" . ">";

etc
0
 
LVL 15

Accepted Solution

by:
a.marsh earned 30 total points
ID: 6351981
Or why not make life easier and change the code to:

for($i = 1; $i < 4; $i++){
  echo "<input type=radio value=$i name=template";
  if($row[template] == $i) echo " checked";
  echo ">";
}


:o)

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6352809
Glad to have helped. :o)

Thanks for the A!

Ant
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Simple PHP/mySQL Query 3 51
nagios 4 php error after installation 6 73
unset shopping cart session 15 29
html input type 3 21
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now