Demonic Posted April 8, 2007 Share Posted April 8, 2007 foreach($_POST['valid'] as $valid){ if($valid){ echo $valid." true<br />"; }else{ echo $valid." false<br />"; } } Alright when I check a field it echos each one true but if its not checked how come its not echoing false? Does this happen so often? (echos 4 inputs, I check 2 only 2 say true and the other 2 won't echo false). Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 8, 2007 Share Posted April 8, 2007 Because you have defined the variable $valid and thus your if statement is always going to return true. Quote Link to comment Share on other sites More sharing options...
Demonic Posted April 8, 2007 Author Share Posted April 8, 2007 Can you please tell me how to do that? Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 youll want to go something like if(isset($value)) or if(!empty($value)) does that help??? Quote Link to comment Share on other sites More sharing options...
Demonic Posted April 8, 2007 Author Share Posted April 8, 2007 No that doesn't help: $array = array(); foreach($_POST['valid'] as $valid){ /* if($valid){ echo $valid." true<br />"; }else{ echo $valid." false<br />"; }*/ ($valid) ? $array[$valid] = "y" : $array[$valid] = "n"; } print_r($array); Array ( [1] => y [3] => y ) Input 1 and input 3 checked.^ Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 soz, im not familiar with that shorthand if Quote Link to comment Share on other sites More sharing options...
jscix Posted April 8, 2007 Share Posted April 8, 2007 Create a function that checks for the input your expecting, since your variable is always gonna be set. Quote Link to comment Share on other sites More sharing options...
Demonic Posted April 8, 2007 Author Share Posted April 8, 2007 Alright im trying to do checkboxes and then if a box is checked make it true else make it false. Do you think ill need to use javascript to update the input value and use an explode? I might have to do that. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2007 Share Posted April 8, 2007 One thing to remember - only the values of checked checkboxes are posted. Quote Link to comment Share on other sites More sharing options...
Zaid Posted April 8, 2007 Share Posted April 8, 2007 lol isn't valid a reserved php keyword? nope Quote Link to comment Share on other sites More sharing options...
Barand Posted April 8, 2007 Share Posted April 8, 2007 nope ??? ??? ??? Quote Link to comment Share on other sites More sharing options...
Demonic Posted April 8, 2007 Author Share Posted April 8, 2007 Alright this what I did: function Gtemplates(){ $skin = mysql_query("SELECT * FROM user_groups"); while($sk = mysql_fetch_array($skin)){ $skinz .= ' <tr> <td class="main_cat_box" width="30%" align="center">'.$sk[name].'</td> <td class="main_cat_box" width="70%" align="center"><input type="checkbox" onClick="if(this.checked==checked){this.value = this.value.split(\'|\')[0]+\'|t\';}else{this.value = this.value.split(\'|\')[0]+\'|f\';}" name="valid[]" value="'.$sk[id].'|f" /></td> </tr> '; } return $skinz; } So it has 4 inputs right? so it switches value BUT I HAVE THE SAME ERROR O_O $array = array(); foreach($_POST['valid'] as $valid){ $valid = explode("|",$valid); ($valid[1] == "t") ? $array[$valid[0]] = "y" : $array[$valid[0]] = "n"; } print_r($array); Array ( [1] => y [4] => y ) input 1 and 4 was checked . Quote Link to comment Share on other sites More sharing options...
tarun Posted April 8, 2007 Share Posted April 8, 2007 Off Topic But Change Topic Title Its Inappropriate My Parents Are In The Same Room Quote Link to comment Share on other sites More sharing options...
Demonic Posted April 8, 2007 Author Share Posted April 8, 2007 Please don't spam.. Quote Link to comment Share on other sites More sharing options...
Demonic Posted April 8, 2007 Author Share Posted April 8, 2007 please bumb :'( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.