php - When I try to echo a posted string, the output is a boolean -
i trying better php skills , when post last name & first name, echo outputs 1 1. no matter put, echo 1 1. why code doing this?
<?php error_reporting(e_all); ini_set('display_errors', '1'); if (isset($_post['firstname'])&& isset($_post['lastname'])){ $firstname=isset($_post['firstname']); $lastname=isset($_post['lastname']); echo $lastname; echo $firstname; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>untitled document</title> </head> <body> <form action="practice2.php" method="post" name="user" > please enter first name: <br> <input type="text" name= "firstname"id="firstname"> <br> please enter last name: <br> <input type="text" name="lastname" id="lastname"> <input type="submit" name="submit"> </form> </body> </html>
the isset method returns boolean, when printed, results in showing 1. want is:
if (isset($_post['firstname'])&& isset($_post['lastname'])){ $firstname = $_post['firstname']; $lastname = $_post['lastname']; echo $lastname; echo $firstname; } you've checked if set in if statement, there's no reason check again within it.
you can see behavior of original code more trying
# output "1". isset returning "true" in original example echo true;
Comments
Post a Comment