seany123 Posted May 13, 2009 Share Posted May 13, 2009 right usually for somthing like this you would use $_POST['quote'] and you would do the same in the query... <input type='text' name='quote' value="<?=$player->quote?>" maxlength='250' size='65'></td> however... using this what do i do?? <select name='ogender'> <option value='1' selected>Male</option> <option value='2'>Female</option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/ Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 $_POST['ogender'] Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833384 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 i tried that but it didnt seem to work. Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833385 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 What's the code? Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833386 Share on other sites More sharing options...
radi8 Posted May 13, 2009 Share Posted May 13, 2009 <select name='ogender'> <option value='1' <?php if($_POST['ogender']==1) print "selected";?>>Male</option> <option value='2'>Female <?php if($_POST['ogender']==2) print "selected";?></option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833389 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 <select name='ogender'> <option value='1' <?php if($_POST['ogender']==1) print "selected";?>>Male</option> <option value='2'>Female <?php if($_POST['ogender']==2) print "selected";?></option> </select> Well no errors there, but the second one is not right. Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833390 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 i tried that but it didnt seem to work. oops apologies this does actually seem to be working Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833391 Share on other sites More sharing options...
radi8 Posted May 13, 2009 Share Posted May 13, 2009 But of course my friend Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833395 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 just quickly though.... does anyone know how do it so if ($player->gender == male) it will have male selected in the form? Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833396 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Look at radi8's example above. Obviously it's an example, but you should know what to do from there. Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833398 Share on other sites More sharing options...
wildteen88 Posted May 13, 2009 Share Posted May 13, 2009 Have a look at radi8's post above. Change $_POST['ogender'] with $player->gender Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833400 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 oh right i see thankyou everyone!! Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833401 Share on other sites More sharing options...
radi8 Posted May 13, 2009 Share Posted May 13, 2009 Assuming that the value in $player->gender is 'male' or 'female', then <select name='ogender'> <option value='1' <?php if ($player->gender == 'male')print "selected";?>>Male</option> <option value='2'>Female <?php if ($player->gender != 'male') print "selected";?></option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833402 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Should be <select name="ogender"> <option value="1" selected="<?php if ($player->gender == 'male') echo "selected";?>">Male</option> <option value="2" selected="<?php if ($player->gender == 'female') echo "selected";?>">Female</option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833405 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 i tried it using this but its sticking on Female. <select name="gender"> <option value="Male" selected="<?php if ($player->gender == 'Male') echo "selected";?>">Male</option> <option value="Female" selected="<?php if ($player->gender != 'Male') echo "selected";?>">Female</option> </select> i have changed a few things like ogender to gender... the values to their names instead of 1,2...etc Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833413 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Which is why I had $player->gender == 'female' in my example. If $player->gender == 'Male' is false, then $player->gender != 'Male' is obviously true. What is the value of $player->gender? Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833416 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 Which is why I had $player->gender == 'female' in my example. If $player->gender == 'Male' is false, then $player->gender != 'Male' is obviously true. What is the value of $player->gender? $player->gender has been "Male", "Female" and "Other" and all 3 times its been hasn't changed which is selected. i just added another option called other... <select name="gender"> <option value="Male" selected="<?php if ($player->gender == 'Male') echo "selected";?>">Male</option> <option value="Female" selected="<?php if ($player->gender != 'Male') echo "selected";?>">Female</option> <option value="Other" selected="<?php if ($player->gender != 'Other') echo "selected";?>">Other</option> </select> now i have 3 its always selecting Other. Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833419 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Fix that up. != Male and != Other? What are those? Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833426 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 okay so now i have <select name="gender"> <option value="Male" selected="<?php if ($player->gender == 'Male') echo "selected";?>">Male</option> <option value="Female" selected="<?php if ($player->gender == 'Male') echo "selected";?>">Female</option> <option value="Other" selected="<?php if ($player->gender == 'Other') echo "selected";?>">Other</option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833428 Share on other sites More sharing options...
Ken2k7 Posted May 13, 2009 Share Posted May 13, 2009 Why do you have 2 Male options? Consider proof-reading your own code. Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833432 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 Why do you have 2 Male options? Consider proof-reading your own code. sorry >.< that hasn't fixed the error yet though... its still selecting "other" Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833434 Share on other sites More sharing options...
radi8 Posted May 13, 2009 Share Posted May 13, 2009 Do an echo $player->gender and see what comes out. <select name="gender"> <option value="Male" selected="<?php if ($player->gender == 'Male') echo "selected";?>">Male</option> <option value="Female" selected="<?php if ($player->gender == 'Female') echo "selected";?>">Female</option> <option value="Other" selected="<?php if ($player->gender == 'Other') echo "selected";?>">Other</option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833437 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 Do an echo $player->gender and see what comes out. <select name="gender"> <option value="Male" selected="<?php if ($player->gender == 'Male') echo "selected";?>">Male</option> <option value="Female" selected="<?php if ($player->gender == 'Female') echo "selected";?>">Female</option> <option value="Other" selected="<?php if ($player->gender == 'Other') echo "selected";?>">Other</option> </select> it echo'd Female Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833441 Share on other sites More sharing options...
wildteen88 Posted May 13, 2009 Share Posted May 13, 2009 The problem is do with empty selected="" attributes. You should only echo "selected="selected" for <options> that should be selected, the remaining <options> should not have a selected attribute. This would be the correct way: <select name="gender"> <option value="Male"<?php if ($player->gender == 'Male') echo " selected=\"selected\"";?>>Male</option> <option value="Female"<?php if ($player->gender == 'Female') echo " selected=\"selected\"";?>>Female</option> <option value="Other"<?php if ($player->gender == 'Other') echo " selected=\"selected\"";?>>Other</option> </select> Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833445 Share on other sites More sharing options...
seany123 Posted May 13, 2009 Author Share Posted May 13, 2009 The problem is do with empty selected="" attributes. You should only echo "selected="selected" for <options> that should be selected, the remaining <options> should not have a selected attribute. This would be the correct way: <select name="gender"> <option value="Male"<?php if ($player->gender == 'Male') echo " selected=\"selected\"";?>>Male</option> <option value="Female"<?php if ($player->gender == 'Female') echo " selected=\"selected\"";?>>Female</option> <option value="Other"<?php if ($player->gender == 'Other') echo " selected=\"selected\"";?>>Other</option> </select> ah i understand... thanks. Link to comment https://forums.phpfreaks.com/topic/157994-instead-of-_post-what-do-i-do/#findComment-833453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.