davanderbilt Posted March 19, 2007 Share Posted March 19, 2007 I have a php form that links up to an Access database where all of the fields are required and one of the fields asks for a date for females only. I can't figure out how to not require a value for this date field (first_day) if the person entering the form is male. I also don't want to have to put in a real date for a value if the person filling out the form is male, because then that means we have inaccurate data in the database. Here is some of the code I'm working with. Here is the gender function that I wrote and reference further below <script type="text/javascript" language="JavaScript"> function gender() { $val=document.dlw.Gender.options[document.dlw.Gender.selectedIndex].value; if($val=="2") { document.dlw.first_day.value="00/00/00"; document.dlw.first_day.disabled=true; } if($val=="1") { document.dlw.first_day.disabled=false; } } </script> I need to be able to make first_day a fillable field only for females, so I created this and have it referencing the gender function above <p align="justify"><strong><span class="style24">Are You Female?</span> <select name="Gender" id="Gender" onChange="gender()"> <option value="1">Yes</option> <option value="2">No</option> </select> </strong></p> <p align="justify"><strong>Females only (Date of first day of menstrual cycle): </strong> (Format:01/01/07) <input name="first_day" type="text" id="first_day" ;" size="10" maxlength="10"> </p> Here is the insert statement to put first_day into the Access database Gender doesn't need to go into the database. I just need it to make the first_day field fillable for females only and the first_day field needs to go into the database. <?php echo '<br><table><tr><td><b>'; foreach ($HTTP_POST_VARS as $key => $value) { $temp = stripslashes($value); $HTTP_POST_VARS[$key] = $temp; if($temp==" ") { $error_rep=1; echo $key,' has not been filled <br/>'; } } echo '</td></tr></table></b>'; $Gender=isset($HTTP_POST_VARS['Gender'])?$HTTP_POST_VARS['Gender']:'NA'; $first_day=isset($HTTP_POST_VARS['first_day']) ? $HTTP_POST_VARS['first_day']:'00/00/0000'; $conn = odbc_connect ('LTE_Master', '', ''); $id= odbc_exec($conn,$get_stat); $insert_statement = " insert into [AccessTable] values ('$first_day')"; if($error_rep==0) { $result = odbc_exec($conn,$insert_statement); if(!$result) { //echo 'There has been error while submitting your survey. Contact...'; ?> </p> <h1 align="center" class="style1"> </h1> <p align="center" class="style1"><font color="#FF0000">There has been an ERROR submitting your Data.</font> </p> <?php } elseif ($result) { ?> The first_day value needs to go into an Access database, where the field type is Date/Time. When I submit, I get the following error: Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression., SQL state 22005 in SQLExecDirect in c:\program files\apache group\apache\htdocs\lte\dlw_add.php on line 157 There has been an ERROR submitting your Data. If I remove the part of the form where it asks if you are female and comment out the gender function, it still gives a data type mismatch if I manually type in 00/00/00 as the first_day date. Then if I manually type in 01/01/01 as the first_day date, the data goes into the database just fine (all of the other field values go in just fine too). I have a lot of other fields on this page and all the others require values, and I am stuck trying to figure out how to not require a value for first_day if the person entering the form is male. I also don't want to have to put in a real date for a value if the person filling out the form is male. Any ideas? Link to comment https://forums.phpfreaks.com/topic/43359-how-can-i-make-a-field-not-required/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.