Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

input type=radio question

Posted on 2001-08-04
3
245 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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