[SOLVED]Radio button checked or not

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cateyes
Forum Commoner
Posts: 63
Joined: Mon Jun 14, 2004 5:06 pm

[SOLVED]Radio button checked or not

Post by Cateyes »

HI guys I am trying to figure out how to show the box is checked or not checked from the data base I am trying to use the if and else statement here is the code which obviously doesn't work

Code: Select all

<?php
Limited Edtion :<?php if($row_rs_stock['LE'] == "Y") 
          <input name="checkbox" type="checkbox" value="checkbox" checked>;
		  else
		  if($row_rs_stock['LE'] == "N")
		  <input name="checkbox" type="checkbox" value="checkbox">; ?>
?>
The problem is that some of this is html code and I can't figure out how to correct it for php if this worked if the value equals yes it would show it checked otherwise N would show it unchecked.
Last edited by Cateyes on Wed Jul 07, 2004 11:31 pm, edited 1 time in total.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

<input name="checkbox" type="checkbox" value="1">
if ($checkbox =='1')
{
#whatever
}
Cateyes
Forum Commoner
Posts: 63
Joined: Mon Jun 14, 2004 5:06 pm

Post by Cateyes »

Not sure I understand your response. The database has a Y or N response how do I use your suggestion if the DB responds with Y I want the box to show its checked otherwise it would be unchecked.
Cateyes
Forum Commoner
Posts: 63
Joined: Mon Jun 14, 2004 5:06 pm

Post by Cateyes »

OK your little post gave me an idea and this is my working code

Code: Select all

<?php
<?php 
		  if($row_rs_stock['LE'] == "Y") { 
          $LEBOX = "checked";
		 } else {
		  if($row_rs_stock['LE'] == "N")
		  $LEBOX = "unchecked"; } ?>
          Limited Edtion :<input name="checkbox" type="checkbox" value="checkbox" <?php echo $LEBOX; ?>>

?>
Post Reply