maliary Posted September 21, 2007 Share Posted September 21, 2007 Hi, Is there a way to check if $_POST has any values ? something like if ($_POST !=' ') ??? Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/ Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 You can use that... if (!$_POST) or if (!isset($_POST)) or if (empty($_POST)) Take a look at each of those functions. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-352326 Share on other sites More sharing options...
MadTechie Posted September 21, 2007 Share Posted September 21, 2007 if(count($_POST) > 0) echo "has values"; or $v=false; foreach($_POST as $P) { if( !empty($P) ) $v=true; } if($v) echo "has values"; Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-352330 Share on other sites More sharing options...
maliary Posted September 21, 2007 Author Share Posted September 21, 2007 I have the following when I print out $_POST Array ( [submit] => Submit [se1] => qqqq [se2] => wwwww [se3] => [se4] => [se5] => [se6] => [se7] => [sid] => 82ea244a6fd9125be1a200a3d211d370 [lang] => en [station] => [dept] => [dept_nr] => 25 [pn] => 45272 [batch_nr] => 955071 [edit] => 0 [target] => admin [subtarget] => baclabor [tracker] => 32 [noresize] => [user_origin] => lab [status] => pending [mode] => save [formtitle] => Bacteriological Laboratory [entry_date] => ) I would like to filter it out and leave only the one's with values e.g. remove [se4] => Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-352335 Share on other sites More sharing options...
Jessica Posted September 21, 2007 Share Posted September 21, 2007 <?php $values = array(); if(count($_POST)){ foreach($_POST AS $k=>$v){ if(isset($v) && strlen(trim($v)){ $values[$k] = trim($v); } } print_r($values); }else{ print 'no posted'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-352339 Share on other sites More sharing options...
HuggieBear Posted September 21, 2007 Share Posted September 21, 2007 In that case I'd probably use foreach ($_POST as $key => $value) { if (empty($v)) { continue; } else { $posted[$key] = $v } } You should have an array ($posted) that just contains the relevant fields. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-352343 Share on other sites More sharing options...
maliary Posted September 21, 2007 Author Share Posted September 21, 2007 I have the following when I print out $_POST Array ( [submit] => Submit [se1] => qqqq [se2] => wwwww [se3] => [se4] => [se5] => [se6] => [se7] => [sid] => 82ea244a6fd9125be1a200a3d211d370 [lang] => en [station] => [dept] => [dept_nr] => 25 [pn] => 45272 [batch_nr] => 955071 [edit] => 0 [target] => admin [subtarget] => baclabor [tracker] => 32 [noresize] => [user_origin] => lab [status] => pending [mode] => save [formtitle] => Bacteriological Laboratory [entry_date] => ) I would like to filter it out and leave only the one's with values e.g. remove [se4] => (This is done! Thanks for the code guys) Then have a string like this sel=jjjjjjj&=se2=hhhhhhhhhh& showing the index and value combination only for those indexes that start with 'se' e.g.[se1] if its blank like this [se4] => don't display it. it should be displayed only when its this way [se4] => www the array element has a value. Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-352421 Share on other sites More sharing options...
maliary Posted September 23, 2007 Author Share Posted September 23, 2007 The solution : <?php $values = array(); if(count($_POST)){ foreach($_POST AS $k=>$v){ if(isset($v) && strlen(trim($v)){ $values[$k] = trim($v); if (k{o} == 's') { if (k{1} == 'e') { $res = $res. $k .'='.$v.'&='; } } } Jesirose, Thanks a Million Times !!!!!!!!!!!!!!!!!! } print_r($values); }else{ print 'no posted'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70158-solved-checking-the-_post/#findComment-353361 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.