Jump to content

instead of $_POST what do i do??


seany123

Recommended Posts

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

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>

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

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.

 

 

 

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>

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>

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

 

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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.