tags:

views:

590

answers:

6

So I have this registration script:

The HTML:

<form action="register.php" method="POST">
    <label>Username:</label> <input type="text" name="username" /><br />
    <label>Password:</label> <input type="text" name="password" /><br />

    <label>Gender:</label>
    <select name="gender">
      <optgroup label="genderset">
        <option value="Male">Male</option>
        <option value="Female">Female</option>
        <option value="Hermaphrodite">Hermaphrodite</option>
        <option value="Not Sure!!!">Not Sure!!!</option>
      </optgroup>
    </select><br />
<input type="submit" value="Register" />
</form>

The PHP/SQL:

<?php

$username = $_POST['username'];
$password = $_POST['password'];
$gender = $_POST['gender'];

mysql_query("INSERT INTO registration_info (username, password, gender) VALUES ('$username', '$password', '$gender')
")  

?>

The problem is, the username and password gets inserted into the "registration_info" table just fine. But the Gender input from the select drop down menu doesn't. Can some one tell me how to fix this, thanks.

A: 

You didn't give any of the options a value, so only an empty string gets inserted.

Ignacio Vazquez-Abrams
Sorry, I forgot to do that when I rewrote the script here, in the original I do have values inside each option, and it still doesn't work.
Richard
A: 

You need to set the value attribute in list items in the HTML.

e.g.

<option value="Male">Male</option>
Paolo
Sorry, I forgot to do that when I rewrote the script here, in the original I do have values inside each option, and it still doesn't work.
Richard
A: 
  1. You have no password input here.
  2. Your gender select box's options have no values.
  3. Use mysql_escape_string at least

    $username = mysql_escape_string($_POST['username']);

or parse to int if you except int value.

$id = (int) $_POST['id'];
hsz
A: 

<?php echo var_dump($_POST['gender']); ?>

Does that tell you anything? Maybe your gender datatype (in your table) is not compatible with what you put into it? Perhaps it's an ENUM('M','F') for example.

Ron
A: 

check the datatype in the database, there could be a mismatch

mouthpiec
A: 

Without tell about security, can you give us the sql script creation of your table

Amirouche Douda