How to insert form data into MySQL database table

Posted by Richard on Stack Overflow See other posts from Stack Overflow or by Richard
Published on 2010-01-30T22:37:31Z Indexed on 2010/05/09 21:18 UTC
Read the original article Hit count: 181

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql