inputting d.o.b drop down form into mysql

hey there, i’ve been trying to sort this out for the past couple of days. i just wind up in the same “error” of no d.o.b entered.
i’m running off of coffee, and brats of mine are crazier than i am at this point.

any help would be appreciated :slight_smile:

[code]

<?php // This script is a query that INSERTs a record in the users table. // Check that form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); // Initialize an error array. // Check for a first name: if (empty($_POST['fname'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = trim($_POST['fname']); } // Check for a last name: if (empty($_POST['lname'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['lname']); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = trim($_POST['email']); } // Check for a birthdate: if (empty($_POST['birthdate'])) { $errors[] = 'You forgot to enter your birthdate.'; } else { $fn = trim($_POST['birthdate']); } // Check for a password and match against the confirmed password: if (!empty($_POST['psword1'])) { if ($_POST['psword1'] != $_POST['psword2']) { $errors[] = 'Your two password did not match.'; } else { $p = trim($_POST['psword1']); } } else { $errors[] = 'You forgot to enter your password.'; } if (empty($errors)) { // If everything's OK. // Register the user in the database... require ('./mysqli_connect.php'); // Connect to the db. // Make the query: $q = "INSERT INTO users (user_id, fname, lname, email, psword, birthdate, registration_date) VALUES (' ', '$fn', '$ln', '$e', SHA1('$p'), '$b', NOW() )"; $result = @mysqli_query ($dbcon, $q); // Run the query. if ($result) { // If it ran OK. header ("location: register-thanks.php"); exit(); // Print a message: //echo '

Thank you!

//

You are now registered. In Chapter 12 you will actually be able to log in!


'; } else { // If it did not run OK. // Public message: echo '

System Error

You could not be registered due to a system error. We apologize for any inconvenience.

'; // Debugging message: echo '

' . mysqli_error($dbcon) . '

Query: ' . $q . '

'; } // End of if ($r) IF. mysqli_close($dbcon); // Close the database connection. // Include the footer and quit the script: //include ('includes/footer.html'); include ('footer.php');
	//header ("location: register-thanks.php"); 
	exit();
} else { // Report the errors.
	//header ("location: register-page.php"); 
	echo '<h2>Error!</h2>
	<p class="error">The following error(s) occurred:<br>';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br>\n";
	}
	echo '</p><h3>Please try again.</h3><p><br></p>';
	}// End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>

Register

First Name:

Last Name:

Email Address:

Birth Date: - Year - 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 - Month - January Febuary March April May June July August September October November December - Day - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 <?php if (isset($_POST['birthdate'])) echo $_POST['birthdate']; ?>" >

Password:

Confirm Password:

[/code]

You don’t have a name in your select is part of the problem (I think) and you can save yourself a lot of typing using PHP code to help you:
[php]<?php
$myDate = new DateTime(“January 1, 1993”, new DateTimeZone(“America/Detroit”)); // Starting Date:
$year = (int) $myDate->format(“Y”); // Get the year force it to be an integer:

?>

Enter Birthday <?php while ($year >= 1947) { // Use a While Loop echo '' . $year . ''; // set the value and display the year: $myDate->modify('-1 year'); // Modify the year to one less year: $year = (int) $myDate->format("Y"); // Force it to integer and set the new year value: } ?> [/php]

close, i had forgotten the value in each “select” box and possibly the script.

now that that allows to register, currently figuring out why the input dates don’t show up in mysql. it yyyy-mm-dd, but shows up with only 000-00-00.

i’m unsure if it is part of what i have above, or the edited section of:

[php]// Check for a birthdate:
if ((empty($_POST[‘year’])) OR (empty($_POST[‘month’])) OR (empty($_POST[‘day’]))) {
$error [] = 1;
$date_e = ‘

* You forgot to enter a date.
’;
} else {
$date_yr = (int)$_POST[‘year’];
$date_mth = (int)$_POST[‘month’];
$date_day = (int)$_POST[‘day’];
    // Use checkdate as insurance that a date was entered
    if (checkdate($date_mth, $date_day, $date_yr)){ 
        $date_pub = $date_yr.'-';
        $date_pub .= $date_mth.'-';
        $date_pub .= $date_day;
    } else {
            $error [] = 1;
            $date_e = '<h5 style="color: red;">* The date was not valid.</h5>';
            }
    }[/php]

In the code you first posted, year is missing a name.

Also, get rid of the @ symbol. Errors are your friend. Dont hide them.

thats most solved, currently having the date show as only 0000-00-00

oh, thanks for seeing that. my bad with the @

also, attached is ss of the db table

[php]

<?php // This script is a query that INSERTs a record in the users table. // Check that form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); // Initialize an error array. // Check for a first name: if (empty($_POST['fname'])) { $errors[] = 'You forgot to enter your first name.'; } else { $fn = trim($_POST['fname']); } // Check for a last name: if (empty($_POST['lname'])) { $errors[] = 'You forgot to enter your last name.'; } else { $ln = trim($_POST['lname']); } // Check for an email address: if (empty($_POST['email'])) { $errors[] = 'You forgot to enter your email address.'; } else { $e = trim($_POST['email']); } // Check for a birthdate: if ((empty($_POST['year'])) OR (empty($_POST['month'])) OR (empty($_POST['day']))) { $error [] = 1; $date_e = '

* You forgot to enter a date.
'; } else { $date_yr = (int)$_POST['year']; $date_mth = (int)$_POST['month']; $date_day = (int)$_POST['day'];
    // Use checkdate as insurance that a date was entered
    if (checkdate($date_mth, $date_day, $date_yr)){ 
        $date_pub = $date_yr.'-';
        $date_pub .= $date_mth.'-';
        $date_pub .= $date_day;
    } else {
            $error [] = 1;
            $date_e = '<h5 style="color: red;">* The date was not valid.</h5>';
            }
    }
		// Check for a password and match against the confirmed password:
if (!empty($_POST['psword1'])) {
	if ($_POST['psword1'] != $_POST['psword2']) {
		$errors[] = 'Your two password did not match.';
	} else {
		$p = trim($_POST['psword1']);
	}
} else {
	$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) { // If everything's OK.
// Register the user in the database...
	require ('./mysqli_connect.php'); // Connect to the db.
	// Make the query:
	$q = "INSERT INTO users (user_id, fname, lname, email, psword, birthdate, registration_date) VALUES (' ', '$fn', '$ln', '$e', SHA1('$p'), '$b', NOW() )";		
	$result = mysqli_query ($dbcon, $q); // Run the query.
	if ($result) { // If it ran OK.
	header ("location: register-thanks.php"); 
	exit();
	// Print a message:
	//echo '<h2>Thank you!</h2>
	//<p>You are now registered. In Chapter 12 you will actually be able to log in!</p><p><br></p>';	
	} else { // If it did not run OK.
	// Public message:
		echo '<h2>System Error</h2>
		<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; 
		// Debugging message:
		echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
	} // End of if ($r) IF.
	mysqli_close($dbcon); // Close the database connection.
	// Include the footer and quit the script:
	//include ('includes/footer.html'); 
	include ('footer.php'); 

	//header ("location: register-thanks.php"); 
	exit();
} else { // Report the errors.
	//header ("location: register-page.php"); 
	echo '<h2>Error!</h2>
	<p class="error">The following error(s) occurred:<br>';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br>\n";
	}
	echo '</p><h3>Please try again.</h3><p><br></p>';
	}// End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>

Register

First Name:

Last Name:

Email Address:

Birth Date: - Year - 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 - Month - January Febuary March April May June July August September October November December - Day - 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 <?php if (isset($_POST['birthdate'])) echo $_POST['birthdate']; ?>

Password:

Confirm Password:

[/php]

Your month and day values are wrong. you have 1,2,3

Should be 01,02,03…

i can try that way again. maybe have the wrong date format for the column…

The date column type should be date.

You dont need all those trims. you can do it one time right after your if POST

$_POST = array_map(‘trim’, $_POST);

Sponsor our Newsletter | Privacy Policy | Terms of Service