Page 1 of 1

syntax problem

Posted: Thu Jan 31, 2008 5:05 am
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

Re: syntax problem

Posted: Thu Jan 31, 2008 5:19 am
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
 

Re: syntax problem

Posted: Thu Jan 31, 2008 5:22 am
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)