validation - Validate multiple empty fields in PHP -


i have following statement validating empty fields in php works fine:

if (isset($_session['logged_in'])) { if (isset($_post['room'], $_post['area'])) {     $room = $_post['room'];     $area = $_post['area'];      if (empty($room) or empty($area)) {         $error = 'required!';     } else {         $query = $pdo->prepare('insert apartments (apartments_room, apartments_area) values (?, ?)');          $query->bindvalue(1, $room);         $query->bindvalue(2, $area);          $query->execute();          header('location: index.php');      } } 

i have opened more columns in database , therefor more insert fields in html validate. question how formulate if statement validation when checking multiple empty fields in case.

so code example doesn't work anymore:

if (isset($_session['logged_in'])) { if (isset($_post['room'], $_post['area'], $_post['rent'], $_post['address'], $_post['floor'], $_post['city'], $_post['freefromdate'])) {     $room = $_post['room'];     $area = $_post['area'];     $rent = $_post['rent'];     $address = $_post['address'];     $floor = $_post['floor'];     $city = $_post['city'];     $freefromdate = $_post['freefromdate'];      if (empty($room) || empty($area) ||  empty($rent) ||  empty($address) ||  empty($floor) ||  empty($city) || empty($freefromdate)) {         $error = 'required!';     } else {         $query = $pdo->prepare('insert apartments (apartments_room, apartments_area, apartments_rent, apartments_address, apartments_floor, apartments_city, apartments_freefromdate) values (?, ?, ?, ?, ?, ?, ?)');          $query->bindvalue(1, $room);         $query->bindvalue(2, $area);         $query->bindvalue(3, $rent);         $query->bindvalue(4, $address);         $query->bindvalue(5, $floor);         $query->bindvalue(6, $city);         $query->bindvalue(7, $freefromdate);          $query->execute();          header('location: index.php');      } } 

how formulate syntax here?

thanks!

change or ||:

if (empty($room) || empty($area) ||  empty($rent) ||  empty($address) ||  empty($floor) ||  empty($city)) { $error = 'required!'; 

http://php.net/manual/en/language.operators.logical.php


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -