Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert form data into MySQL database table

Tags:

php

mysql

insert

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.

like image 433
Richard Avatar asked Nov 25 '22 21:11

Richard


1 Answers

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

like image 54
mouthpiec Avatar answered Nov 28 '22 09:11

mouthpiec