Accurax Posted January 10, 2007 Share Posted January 10, 2007 Simple question here guys...I have a form that allows a user to input information about themselves, now the first time they use this form all the firleds will be blank.... but id like them to be able to come back and update the information.Is there anyway of making the form show the info that is held in the database for a given field?Thanks chaps Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 what you need to do is to read the information off your data first, do you use mysql or text files?Ted Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 yup! just set a value to the fields...for example...[code]<input type=text value="<?=$_POST[test]?>" name="test">[/code] Quote Link to comment Share on other sites More sharing options...
Accurax Posted January 10, 2007 Author Share Posted January 10, 2007 Ahh... excellentWould that work with drop down menu's and the "selected" attribute aswell ??How about radio buttons and check box's ? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 radio:[code]<?php function check($a,$b){if($a == $b){echo "checked=\"yes\"";}}?>eg form:<input type="radio" name="test" value="a" <?php check("a",$b)?>>drop down:<select name="birthday" size="1"><?php $bdays = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31',);$bday_select = "";foreach ($bdays as $bdays){$bday_select .= '<option value="' . $bdays . '"';if ($bdays == $birthday) {$bday_select .= ' selected';}$bday_select .= '>' . $bdays . '</option>';}echo"$bday_select";?></select>[/code]where as $birthday is your stored variable.Ted Quote Link to comment Share on other sites More sharing options...
Accurax Posted January 10, 2007 Author Share Posted January 10, 2007 OUch... thats confused me now ......... can i not just use SELECT in the drop down menu "selected" attribute? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 10, 2007 Share Posted January 10, 2007 If this is easier for you to understand:<?php function check($a,$b){if($a == $b){echo " selected=\"selected\"";}}?><select name="test"><option value="1" <?php check("1",$b)?>>Test1</option><option value="2" <?php check("2",$b)?>>Test2</option><option value="3" <?php check("3",$b)?>>Test3</option><option value="4" <?php check("4",$b)?>>Test4</option></select> Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 yup... you can do it that way too if you want... but it if you were wanting your page more automated... you'd prolly want somin like this....[code]<?function form_autodropbox($to=array(),$selected="",$name=""){ if(!is_array($to)) return FALSE; $return .= '<select name="'.$name.'">'; foreach($to as $k => $v){ if($k==$selected) $return .= '<option selected value="'.$v.'">'.ucwords($k).'</option>'; else $return .= '<option value="'.$v.'">'.ucwords($k).'</option>'; } $return .= '</select>'; return $return;}$to[test]="asdf";$to[test2]="asdf";$to[test3]="asdf";$to[test4]="asdf";echo form_autodropbox($to,"test3",'test')?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.