What is the most efficient way to check if POST variables have been set?
For example, I collect 10 variables from Page 1 , if they are set, I would like to save this data on Page 2 . If not, I would designate "inaccessible."
I am currently using if !empty
, but it seems like there should be a simpler / more efficient method, I'm pretty new to php, so any advice is welcome.
Code example;
if (!empty($_POST["book"])) { $book= $_POST['book']; }else{ $book= 'not available'; } if (!empty($_POST["author"])) { $author = $_POST['author']; }else{ $author= 'not available'; } if (!empty($_POST["subtitle"])) { $subtitle= $_POST['subtitle']; }else{ $subtitle= 'not available'; } etc... etc... etc...
source share