Jump to content

date of birth


batstanggt

Recommended Posts

hey guys heres my current registration script how does one enter d.o.b ? And what is the proper format in the mysql table?

<form name="login" method="post" action="registration.php">
<table border="5" width="377" align="center" bordercolor="#00CC00">
    <tr>
        <td width="219" bgcolor="#00cc00">
            <p align="center"><font color="white"><span style="font-size:12pt;"><b>Registration</b></span></font></p>
        </td>
    </tr>
    <tr>
        <td width="219">
            <table border="0" width="282" align="center">
                    <tr>
                        <td width="116"><span style="font-size:10pt;">Name:</span></td>
                        <td width="156"><input type="text" name="name" maxlength="100"></td>
                    </tr>
                    <tr>
                        <td width="116"><span style="font-size:10pt;">Email:</span></td>
                        <td width="156"><input type="text" name="email" maxlength="100"></td>
                    </tr>
                <tr>
                    <td width="116"><span style="font-size:10pt;">Username:</span></td>
                    <td width="156"><input type="text" name="username"></td>
                </tr>
                <tr>
                    <td width="116"><span style="font-size:10pt;">Password:</span></td>
                    <td width="156"><input type="password" name="password"></td>
                </tr>
                <tr>
                    <td width="116"> </td>
                        <td width="156">
                            <p align="right"><input type="submit" name="submit" value="Submit"></p>
                        </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td width="219" bgcolor="#00cc00"> </td>
    </tr>
</table>
</form>

thats the html and heres the .php

<?PHP

//Database Information

$dbhost = "localhost";
$dbname = "mydatabase";
$dbuser = "root";
$dbpass = "rootpass";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

    
$name = $_POST['name'];
$email = $_POST['email'];    
$username = $_POST['username'];
$password = md5($_POST['password']);

// lets check to see if the username already exists

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'"); 

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
    echo "I'm sorry but the username you specified has already been taken.  Please pick another one.";
    unset($username);
    include 'register.html';
    exit();
} 

// lf no errors present with the username
// use a query to insert the data into the database.

$query = "INSERT INTO users (name, email, username, password)
VALUES('$name', '$email', '$username', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "You have successfully Registered";
    
// mail user their information

$yoursite = 'www.abcd.com';
$webmaster = 'Sdot';
$youremail = 'emailaddy';
    
$subject = "You have successfully registered at $yoursite...";
$message = "Dear $name, you are now registered at our web site.  
    To login, simply go to our web page and enter in the following details in the login form:
    Username: $username
    Password: $password
    
    Please print this information out and store it for future reference.
    
    Thanks,
    $webmaster";
    
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
    
echo "Your information has been mailed to your email address.";

?>

Any help would b great

Link to comment
Share on other sites

in my opinion it is best you save the date as a string

 

Based on?

 

-A MySQL Date requires 3 Bytes of storage

-You can do Date arithmetic inside mysql (search for dates within ranges)

-It intrinsically will only store valid dates

-You can format it in numerous ways

 

-A string will require minimum 8 bytes, or 10 with seperators

-can't do any form of range queries

-can't format it in SQL

-will allow completely invalid dates

 

 

Link to comment
Share on other sites

yes it does require more space but it's easily breakable and incorrect dates would not be stored .. checkdate() it's just my opinion, guess I'm better at working with strings, that's why I like it better.

 

 

Client side validation can be done regardless of the data type.  That is not relevant or an argument for storing a date in mysql as a string.

 

You didn't present a single benefit to storing things as a string.  In terms of database query performance, flexibility, and storage requirements, I listed a series of problems using strings, and benefits to using a Date type. 

 

Should we then assume that you aren't really able to pinpoint any advantages to storing a string other than that a string will store invalid dates?  (Which is a benefit in what way?)

 

It's fine to do something because that's what you know, but you'll be a far better developer in the long term if you open your mind to alternatives, and research and consider different ways of doing things.  Preferring to do something a particular way because that's all you know, is not an argument in support of your opinion.

Link to comment
Share on other sites

The flurry of activity is greatly appreciated. I dont have alot of experience with strings and despite the fact manix that your suggestion did not go unconsidered based upon my own skillset I think I will use the DATE column, and perhaps a drop down menu in the register table to select the date so that way invalid dates arent even an option for the user to enter, if you catch my drift. Silkfire yes i would love to know how to calculate age based on todays date that would be fantastic. Also could someone show me how to create drop down menus for year, month, and day. Anyone else can feel free to chime in with these answers as well hahaha. Thanks again guys.

-SB

Link to comment
Share on other sites

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.