if (empty($_POST['title'])) { echo "empty"; } PHP: With my above code, I want to check if $_POST['title'], $_POST['link_description'] and a few others are empty or not, instead of repeating the above code can I use like a comma or something somewhere so I can just do $_post['title'], $_post['link_description'] ..etc Thanks
You can use for example such a short construction: if (!@$_POST['title'] || !@$_POST['link_description'] || !@$_POST['field3']) echo "Wrong input"; PHP:
Sure, just use a loop. $requiredFields = array('title','link_description','and_so_on'); foreach ( $requiredFields as $field ) { if ( empty($_POST[$field]) ) { echo $field. ' is empty'; } } PHP:
That's easier for a few fields, but for a lot of fields use the loop.. little explanation for in the future if (somthing == something_else || blablsfsdf == adas && as==asd) { } PHP: || means OR && means AND
foreach ($_POST as $key => $value) if($value == NULL){ $error .= 'Please enter a value for the '.$key.' field';} } if($error == NULL){ //do your post stuff here } PHP: Peace,