syntax problem

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
itarun
Forum Newbie
Posts: 7
Joined: Fri Jan 25, 2008 9:22 am

syntax problem

Post by itarun »

hi friends this code were using in the update form but it not working properly where "$dd is nothing but num_fetch _array rows and rgender is nothing but database field name"
<input type="radio" name="sex" <?php if($dd['rgender']=="male") {?> checked <?php } ?> id="male" value="male">male &nbsp;
<input type="radio" name="sex" <?php if($dd['rgender']=="female"){?> checked <?php } ?> id="female" value="female">female
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: syntax problem

Post by aceconcepts »

What you could do is set a "checked" variable outside of the form element:

i.e.

Code: Select all

 
<?php 
$mChecked="";
$fChecked="";
 
if($dd['rgender']=="male") {
   $mChecked="checked"; 
} elseif($dd['rgender']=="female") {
   $fChecked="checked"; 
}
 ?>
<input type="radio" name="sex" <?php echo $mChecked; ?> id="male" value="male">male &nbsp;
<input type="radio" name="sex" <?php echo $fChecked; ?> id="female" value="female">female
 
User avatar
JamesRavenscroft
Forum Newbie
Posts: 10
Joined: Thu Jan 31, 2008 3:45 am
Location: West Midlands, United Kingdom

Re: syntax problem

Post by JamesRavenscroft »

Hey itarun

Have you made sure that there is no error in your mysql query? Be sure to do a "print mysql_error();" to make sure this is not the case.

Also, see if there is anything in the $dd array by doing "print_r($dd);"

That will print all of the data (if any) in that variable like Array(key => value, key=> value)
Post Reply