I've created a PHP form that collects information from the user using the $_GET variable in PHP. This code then outputs what the user filled in on another page. However I want it to print 'N/A' if the user leaves a space empty. I've tried using, if ($firstname==' ' && $secondname==' ' && $email==' ' && $phone==' ' && $age==' ' && $position==' ' && $company==' '){ echo 'N/A'; } What's wrong with this? Why wont it print 'N/A'. I've created the variables $firstname = $_GET['name']; Thanks
' ' - that has a space. That's not empty. <?php if (empty($firstname) && empty($secondname) && empty($email) && empty($phone) && empty($age) && empty($position) && empty($company)) { echo 'N/A'; } ?> PHP:
Using $_GET-variables, you should always check to see if they're set - proper syntax for checking would be something like this: $firstname = (isset($_GET['firstname'])) ? $_GET['firstname'] : 'N/A'; Then you just use the $firstname-var whereever you need to display either content.
Hello, If you want to check if one of the variables has not been set you should use || istead of && on the syntax: <?php if (empty($firstname) || empty($secondname) || empty($email) || empty($phone) || empty($age) || empty($position) || empty($company)) { echo 'N/A'; } ?> PHP:
Ok, thanks for the reply. Sorry if I sound a bit stupid I'm only 14 years old and only just learning PHP. Thanks
If you want to learn PHP, a website that will teach you at least the basics and more is CodeAcademy.com .. check it out. You might find it worthy of your time.