Jump to content

Recommended Posts

<?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...

Link to comment
https://forums.phpfreaks.com/topic/171807-problem-with-registration-code/
Share on other sites

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...

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.

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.