Jump to content

problem with registration code


Noskiw

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 value="Male">Male</option>
				<option value="Female">Female</option>

			</select>

		</td>

	</tr>

</table></p>

<div align="right"><input type="submit" name="submit" value="Register" /></div>

</form>

<?php

include ("design/footer.php");

?>

 

i have a problem with the switch statement. it doesn't actually register the male or female category....

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

echo $gender before the switch statement and make sure it actually has data in it.

 

By the way, using a switch statement with 2 possible tests is kind of pointless. Switch is usually used when you have many tests that need to be preformed (I usually use them for over 3 or 4) and your code would get nasty with all the if statements. For your case, you could shrink that case statement to one line, using a ternary operator (http://us2.php.net/ternary)

 

$genderdb = ($gender = "Male") ? "M" : "F";

 

 

Archived

This topic is now archived and is closed to further replies.

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