Noskiw Posted August 25, 2009 Share Posted August 25, 2009 <?php include ("design/header.php"); require ("connect.php"); if ($_POST['submit']) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; $password = $_POST['password']; $password_repeat = $_POST['password_repeat']; $dob_year = $_POST['dob_year']; $dob_month = $_POST['dob_month']; $dob_day = $_POST['dob_day']; $gender = $_POST['gender']; if ($firstname && $lastname && $username && $password && $password_repeat && $dob_year && $dob_month && $dob_day && $gender) { if (strlen($username) > 25 || strlen($firstname) > 25 || strlen($lastname) > 25) { echo "Your first name, last name, and username must be no more than 25 characters each!"; } else { if (strlen($password) > 25 || strlen($password) < 6) { echo "Your password must be between 6 and 25 characters!"; } else { if (is_numeric($dob_year) && is_numeric($dob_month) && is_numeric($dob_day)) { if (strlen($dob_year) > 4 || strlen($dob_month) > 2 || strlen($dob_day) > 2) echo "Date of birth year must be 4 characters and the day and month must be 2!"; else if ($gender == "Male" || $gender == "Female") { if ($password == $password_repeat) { if ($dob_month > 12 || $dob_day > 31) { echo "Date of birth month of day is bigger than expected!"; } else { $dob_db = "$dob_year-$dob_day-$dob_month"; $password_db = md5($password); switch ($gender) { case "Male": $genderdb = "M"; break; case "Female": $genderdb = "F"; break; } $register = mysql_query("INSERT INTO users VALUES('','$firstname','$lastname','$username','$password_db','$dob_db','$genderdb')"); echo "Success!"; } }else { echo "Passwords do not match!"; } } else { echo "Gender must be male or female!"; } } else { echo "Date of birth must be in number form! For example... 1978/11/06"; } } } } else { echo "Missing Field"; } } else { echo "Please enter your details and click register."; } ?> <form action="register.php" method="POST"> <p><table width="60%"> <tr> <td width="40%" align="right"> <font size="2" face="arial">First Name: </font> </td> <td> <input type="text" name="firstname" value="<?php echo $firstname; ?>" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Last Name: </font> </td> <td> <input type="text" name="lastname" value="<?php echo $lastname; ?>" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Username: </font> </td> <td> <input type="text" name="username" value="<?php echo $username; ?>" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Password: </font> </td> <td> <input type="password" name="password" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Repeat Password: </font> </td> <td> <input type="password" name="password_repeat" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Date of Birth </font> </td> <td> <input type="text" name="dob_year" maxlength="4" size="3" value="<?php if ($dob_year) echo $dob_year; else echo "YYYY" ?>" /> / <input type="text" name="dob_month" maxlength="2" size="1" value="<?php if ($dob_day) echo $dob_day; else echo "DD"; ?>" /> / <input type="text" name="dob_day" maxlength="2" size="1" value="<?php if ($dob_month) echo $dob_month; else echo "MM"; ?>"/> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Gender: </font> </td> <td> <select name="gender"> <option>Female</option> <option>Male</option> </select> </td> </tr> </table></p> <div align="right"><input type="submit" name="submit" value="Register" /></div> </form> <?php include ("design/footer.php"); ?> the gender will not input for me. it shows up as a zero in the mysql database... Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/ Share on other sites More sharing options...
Noskiw Posted August 25, 2009 Author Share Posted August 25, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905944 Share on other sites More sharing options...
PFMaBiSmAd Posted August 25, 2009 Share Posted August 25, 2009 You need value="..." attribute in the <option > tag if you want to get a value from the form - http://w3schools.com/html/tryit.asp?filename=tryhtml_select2 Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905948 Share on other sites More sharing options...
Noskiw Posted August 25, 2009 Author Share Posted August 25, 2009 NEW CODE: <?php include ("design/header.php"); require ("connect.php"); if ($_POST['submit']) { $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; $password = $_POST['password']; $password_repeat = $_POST['password_repeat']; $dob_year = $_POST['dob_year']; $dob_month = $_POST['dob_month']; $dob_day = $_POST['dob_day']; $gender = $_POST['gender']; if ($firstname && $lastname && $username && $password && $password_repeat && $dob_year && $dob_month && $dob_day && $gender) { if (strlen($username) > 25 || strlen($firstname) > 25 || strlen($lastname) > 25) { echo "Your first name, last name, and username must be no more than 25 characters each!"; } else { if (strlen($password) > 25 || strlen($password) < 6) { echo "Your password must be between 6 and 25 characters!"; } else { if (is_numeric($dob_year) && is_numeric($dob_month) && is_numeric($dob_day)) { if (strlen($dob_year) > 4 || strlen($dob_month) > 2 || strlen($dob_day) > 2) echo "Date of birth year must be 4 characters and the day and month must be 2!"; else if ($gender == "Male" || $gender == "Female") { if ($password == $password_repeat) { if ($dob_month > 12 || $dob_day > 31) { echo "Date of birth month of day is bigger than expected!"; } else { $dob_db = "$dob_year-$dob_day-$dob_month"; $password_db = md5($password); switch ($gender) { case "Male": $genderdb = "M"; break; case "Female": $genderdb = "F"; break; } $register = mysql_query("INSERT INTO users VALUES('','$firstname','$lastname','$username','$password_db','$dob_db','$genderdb')"); echo "Success!"; } }else { echo "Passwords do not match!"; } } else { echo "Gender must be male or female!"; } } else { echo "Date of birth must be in number form! For example... 1978/11/06"; } } } } else { echo "Missing Field"; } } else { echo "Please enter your details and click register."; } ?> <form action="register.php" method="POST"> <p><table width="60%"> <tr> <td width="40%" align="right"> <font size="2" face="arial">First Name: </font> </td> <td> <input type="text" name="firstname" value="<?php echo $firstname; ?>" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Last Name: </font> </td> <td> <input type="text" name="lastname" value="<?php echo $lastname; ?>" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Username: </font> </td> <td> <input type="text" name="username" value="<?php echo $username; ?>" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Password: </font> </td> <td> <input type="password" name="password" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Repeat Password: </font> </td> <td> <input type="password" name="password_repeat" maxlength="25" /> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Date of Birth </font> </td> <td> <input type="text" name="dob_year" maxlength="4" size="3" value="<?php if ($dob_year) echo $dob_year; else echo "YYYY" ?>" /> / <input type="text" name="dob_month" maxlength="2" size="1" value="<?php if ($dob_day) echo $dob_day; else echo "DD"; ?>" /> / <input type="text" name="dob_day" maxlength="2" size="1" value="<?php if ($dob_month) echo $dob_month; else echo "MM"; ?>"/> </td> </tr> <tr> <td width="40%" align="right"> <font size="2" face="arial">Gender: </font> </td> <td> <select name="gender"> <option value="Female">Female</option> <option value="Male">Male</option> </select> </td> </tr> </table></p> <div align="right"><input type="submit" name="submit" value="Register" /></div> </form> <?php include ("design/footer.php"); ?> unfortunately... it didn't work... Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905951 Share on other sites More sharing options...
Noskiw Posted August 25, 2009 Author Share Posted August 25, 2009 bumpety bump Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905963 Share on other sites More sharing options...
mikesta707 Posted August 25, 2009 Share Posted August 25, 2009 what happens when you run this? how exactly does it "not work" Does nothing enter into the database? incorrect values? Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905967 Share on other sites More sharing options...
Noskiw Posted August 25, 2009 Author Share Posted August 25, 2009 they're the correct values but i just can't seem to get the correct value in the database. Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905971 Share on other sites More sharing options...
PFMaBiSmAd Posted August 25, 2009 Share Posted August 25, 2009 And what exactly have you done to troubleshoot what your code is doing on your server with your database. The code you posted produces the following INSERT query using some dummy data entered in the form - INSERT INTO users VALUES('','a','b','c','e10adc3949ba59abbe56e057f20f883e','9-8-7','F') Your Date of Birth form fields are ambiguous given that you will get different people with different backgrounds that will put the day and the month in different order. You are also not validating that the entered date is a date. You are echoing the "Success!" message without actually checking that the query executed and that a row was inserted. If your table is setup with unique keys to prevent duplicate data from being entered (you don't want people selecting usernames that have already been taken do you?), your query would fail due to a duplicate key value. Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905976 Share on other sites More sharing options...
Russia Posted August 25, 2009 Share Posted August 25, 2009 Bro, stop bumping your thread after 10 fucking minutes. Its annoying when others are trying to get help also. Its called Google. Make it show errors and search your error on Google. Quote Link to comment https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/#findComment-905978 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.