Jump to content

Recommended Posts

I've created a form, on this form is a dropdown box with the name male (value=m) and female (value=f).

Once the form is submitted I am able to retrieve all the input data from the text fields - however the dropdown field always shows up as blank.

I'm using...

$gender=$_POST['gender'];

...to retrieve the values in a variable,

Any idea what I could be doing wrong?
Link to comment
https://forums.phpfreaks.com/topic/11410-retrieves-blank-data-from-dropdown-box/
Share on other sites

It would help if you posted the code for the drop-down. It sounds like you're not putting any values in the options... you're just echoing the selections between the option tags.

You should have:
<option value="male">male</option>

It sounds like you have:
<option>male</option> or just <option>male
Heres the registration form:
[code]<form name="register" method="post" action="addme.php">
  <label>
  <p align="center">Requested Username<br>
      <input type="text" name="username" tabindex="1">
  </p>
  <p align="center">
    <label>Password<br>
    <input type="password" name="password" tabindex="2">
    </label>
  </p>
  <p align="center">
    <label>Verify Password<br>
    <input type="password" name="password2" tabindex="3">
    </label>
  </p>
  <p align="center">
    <label>Email<br>
    <input type="text" name="email" tabindex="4">
    </label>
  </p>
  <p align="center">
    <label>Gender<br>
    <select name="gender" tabindex="5">
      <option value="m">Male</option>
      <option value="f">Female</option>
    </select>
    </label>
  <p align="center">
    <input type="submit" name="Submit" value="Submit" tabindex="6">
</p>
</form>
[/code]

And here is part of the .php that processes it:
[code]
...
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$joined=date("y-m-d");
...
[/code]

When I echo or print $gender its blank

See any problems?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.