redarrow Posted May 3, 2006 Share Posted May 3, 2006 advance thank you.I am using a date array function, and i wont the user to be able to say if they have any dates not to usevia a yes and no check box.The varables for dates is:[code]$date1$date2$date3$date4[/code][code]<input name="dates" type="checkbox" value="yes">Yes<input name="dates" type="checkbox" value="no">no[/code]how do i get a valadition to see if the user has said no then dont insert to database, And if yes insert to database.example only[code]if ($dates =="no") {$date1 $date2 $date3 $date4}else{ if($dates =="yes") {$date1 $date2 $date3 $date4INSERT INTO DATABASE}}[/code]So how do i join a no or yes to a corrersponding code.or is this a existing proper code[code]if(($dates=="no")==($date1 && $date2 && $date3 && $date4)){do nothink}if(($dates=="yes")==($date1 && $date2 && $date3 && $date4)){INSERT INTO DATABASE}[/code] Link to comment https://forums.phpfreaks.com/topic/8967-yes-no-valadation-on-check-box/ Share on other sites More sharing options...
craygo Posted May 3, 2006 Share Posted May 3, 2006 Might be better of using a radio button rather than a check box[code]YES<input type=radio name=date1r value=yes> NO<input type=radio name=date1r value=no>YES<input type=radio name=date2r value=yes> NO<input type=radio name=date2r value=no>YES<input type=radio name=date3r value=yes> NO<input type=radio name=date3r value=no>YES<input type=radio name=date4r value=yes> NO<input type=radio name=date4r value=no>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/8967-yes-no-valadation-on-check-box/#findComment-32951 Share on other sites More sharing options...
redarrow Posted May 3, 2006 Author Share Posted May 3, 2006 Ray how to valadate a yes or no for the $date to be inserted to database mateexample all as one so if they press yes the insert goes if they press no the insert dosent go.your code correct and nice thank you but one yes and one no ok[code]<input type=radio name=dates value=yes>Yes<input type=radio name=dates value=yes>NO[code]what is the correct syntex code to join all as one together to valadateexample does this join a yes or no together with $dates. if(($dates=="no")==($date1r && $date2r && $date3r && $date4r)){do nothink}if(($dates=="yes")==($date1r && $date2r && $date3r && $date4r)){INSERT INTO DATABASE}[/code] Link to comment https://forums.phpfreaks.com/topic/8967-yes-no-valadation-on-check-box/#findComment-32954 Share on other sites More sharing options...
craygo Posted May 3, 2006 Share Posted May 3, 2006 What is the structure for the table where the dates will be inserted??Ray Link to comment https://forums.phpfreaks.com/topic/8967-yes-no-valadation-on-check-box/#findComment-32959 Share on other sites More sharing options...
redarrow Posted May 3, 2006 Author Share Posted May 3, 2006 this on check.phpif you press yes echo yes if you press no echo no is this correct not working[code]if(!$datecheck=="yes") {echo "yes";exit;}if(!$datecheck=="no") {echo "no";exit;}[/code]this on post.php[code]<input name="datecheck" type="checkbox" value="yes">Yes<input name="datecheck" type="checkbox" value="no">no[/code] Link to comment https://forums.phpfreaks.com/topic/8967-yes-no-valadation-on-check-box/#findComment-32964 Share on other sites More sharing options...
redarrow Posted May 3, 2006 Author Share Posted May 3, 2006 [!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]solved[!--sizec--][/span][!--/sizec--]If the user press yes the database gets the dates, But if the user press no the user gets defult dates.[code]if($datecheck=="yes") {$days = array();$month = array();$years = array();foreach($_POST as $key => $value){if (substr($key, 0, 5) == 'month'){$months[]=$value;}if (substr($key, 0, 3) == 'day'){$days[].=$value;}if (substr($key, 0, 4) == 'year'){$years[]=$value;}}$dates1 = ''.$days[0].'-'.$months[0].'-'.$years[0].'';$dates2 = ''.$days[1].'-'.$months[1].'-'.$years[1].'';$dates3 = ''.$days[2].'-'.$months[2].'-'.$years[2].'';$dates4 = ''.$days[3].'-'.$months[3].'-'.$years[3].'';INSERT INTO DATABASE}if($datecheck=="no") {$dates1 ="0-0-0000";$dates2 ="0-0-0000";$dates3 ="0-0-0000";$dates4 ="0-0-0000";INSERT INTO DATABASE}[/code] Link to comment https://forums.phpfreaks.com/topic/8967-yes-no-valadation-on-check-box/#findComment-32975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.