Earlier today I created simple database (user and login fields), login, and registration PHPs.

Now I need help going about the following enhancement:
In a nutshell: I am trying to create a registration form like facebook's with php code (and link it a mysql database)...

1.) My updated registration.php has 5 fields:
"Full Name" (text)(40)
"Your Email" (which is equal to username for my site's login, use text? not sure?)(40)
"Create Password" (text)(40)
"Birthday" (3 drop downs with following options: (Month: ) "Jan thru Dec", (Day: ) "1 thru 31", (Year: ) 1933 thru 2008
"Gender" (single drop down with 2 options: "female", "male")
I have no clue for adding the birthday and gender dropdowns to mySQL because of their drop down options.

Here is what my code looks like (please share if you see any errors, some of my code was grabbed from web so I really am not sure if the "post"s are setup correctly now).

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td><FONT FACE="Rockwell" color="#666666" SIZE="2">Full Name</FONT></td><td><input type="text" name="name" maxlength="40"></td></tr>
<tr><td><FONT FACE="Rockwell" color="#666666" SIZE="2">Your Email</FONT></td><td><input type="text" name="user" maxlength="30"></td></tr>
<tr><td><FONT FACE="Rockwell" color="#666666" SIZE="2">Create Password</td><td><input type="password" name="pass" maxlength="30"></td></tr>
<tr><td><FONT FACE="Rockwell" color="#666666" SIZE="2">Birthday</FONT></td><td>
    <select name="update_mybirthmonth">
        <option value='1'>Jan</option>
        <option value='2'>Feb</option>
        <option value='3'>Mar</option>
        <option value='4'>Apr</option>
        <option value='5'>May</option>
        <option value='6'>Jun</option>
        <option value='7'>Jul</option>
        <option value='8'>Aug</option>
        <option value='9'>Sep</option>
        <option value='10'>Oct</option>
        <option value='11'>Nov</option>
        <option value='12'>Dec</option>
    <select name="update_mybirthday">
        <? for($i = 1; $i <= 31; $i++) : ?>
            <option value="<?=$i;?>"><?=$i;?></option>
        <? endfor; ?>
    <select name="update_mybirthyear">
        <? for($i = 1933; $i <= 2008; $i++) : ?>
            <option value="<?=$i;?>"><?=$i;?></option>
        <? endfor; ?>
<tr><td><FONT FACE="Rockwell" color="#666666" SIZE="2">Gender</FONT></td><td>
    <select name="update_mybirthmonth">
        <option value='1'>female</option>
        <option value='2'>male</option>
<tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Sign Up"></td></tr>
    $update_mybirthmonth = $_POST['update_mybirthmonth'];
    $update_mybirthday = $_POST['update_mybirthday'];
    $update_mybirthyear = $_POST['update_mybirthyear'];
    if (($update_mybirthmonth >= 1) AND ($update_mybirthmonth >= 1) AND ($update_mybirthday >= 1) AND ($update_mybirthday <= 31) AND ($update_mybirthyear >= 0) AND ($update_mybirthyear <= $this_year))
        include 'functions/DbConnector.php';
        $birthday = "$update_mybirthmonth-$update_mybirthday-$update_mybirthyear";
        mysql_query("UPDATE login SET birthday = '$birthday' WHERE username = 'Valerij'") or die ("Database error: ".mysql_error());

Does anyone know the code for creating a mySQL database that can grab from this information?

How do I fix the php inside this file to correlate to the newly created mySQL database?

Votes + Comments
$11 ? ...that is why we are here and answering.. to take yours 11 dollars ...
6 Years
Discussion Span
Last Post by petr.pavel

Hi Jacob,
the query for creating the database would be
create table login
`name` varchar(255),
`user` varchar(255),
`pass` varchar(255),
`birthday` date;

Please consider encrypting the password using MySQL function PASSWORD(). If your site gets hacked you won't compromise your users passwords. (It will be enough that the hacker gets their e-mails.)

I'm confused by the latest query. It uses a field 'username' but you ask for 'user'.
Also, the WHERE clause contains a hard coded value, I guess you were just testing.

I'm not sure if you know that UPDATE is for changing an existing record. INSERT is for creating a new one. If this is a 'register new account' kind of form then you want to use INSERT and not UPDATE here.

I don't see where you combine
$update_mybirthmonth, $update_mybirthday and $update_mybirthyear into $birthday.
I guess you wanted to write something like

$birthday = $update_mybirthyear.'-'.$update_mybirthmonth.'-'.$update_mybirthday;

Instead of the sequence of >=1 <= 31 (which doesn't take into account variability of number of days per month), try PHP function checkdate().

The gender select box has a wrong name. It's called update_mybirthmonth which eventually overwrites the previous select box' value.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.