batstanggt Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/ Share on other sites More sharing options...
Pikachu2000 Posted August 1, 2011 Share Posted August 1, 2011 Not sure what you're really asking here. Do you want suggestions on how to set up the form fields, or what? Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250046 Share on other sites More sharing options...
batstanggt Posted August 1, 2011 Author Share Posted August 1, 2011 My question was somewhat two pronged I was yes lookin for suggestions on the form and then i was also inquiring as to what the correct way to store a date (ie. format 06/29/1988 vs. 1988-06-29 etc...). -SB Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250191 Share on other sites More sharing options...
batstanggt Posted August 1, 2011 Author Share Posted August 1, 2011 anybody? Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250231 Share on other sites More sharing options...
silkfire Posted August 1, 2011 Share Posted August 1, 2011 1988-06-29 is the best standard. Do you also wanna know how to calculate someone's age today base on a date? Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250317 Share on other sites More sharing options...
gizmola Posted August 1, 2011 Share Posted August 1, 2011 The best way in mysql is to use a mysql DATE column. Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250318 Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 in my opinion it is best you save the date as a string Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250382 Share on other sites More sharing options...
gizmola Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250386 Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250388 Share on other sites More sharing options...
gizmola Posted August 1, 2011 Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250394 Share on other sites More sharing options...
manix Posted August 1, 2011 Share Posted August 1, 2011 I guess you are right. Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250396 Share on other sites More sharing options...
batstanggt Posted August 2, 2011 Author Share Posted August 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243434-date-of-birth/#findComment-1250534 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.