Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


"isset" not working :-(

"isset" not working :-(

"isset" not working :-(

Hi everyone,
A very simple code that aims to know whether value was inserted to an input field in a form is not working sad.
In the following code, when a value is inserted to field 'A" I want 'a' to be echoed and if 'b' recieves value the program should
show 'b' on the display.
Whether I insert a value or weather no value is inserted at all the following program always shows shows both 'a' and 'b'.
Can anyone help me with mnaking that program show 'a' only when 'a' was inserted value and 'b' only when be was inserted value?


<?php //myIsset.php
$a = '';
$b = '';
if (isset($_GET['a'])) echo 'a<br>';
if (isset($_GET['b'])) echo 'b';

echo '
<!DOCTYPE html>
<html lang = "en">
  <meta charset="utf-8" />

  <form action = "myIsset.php" method = "GET">
    A <input type ="text" name = "a">
    B <input type ="text" name = "b">
    <input type = "submit" value = "convert">
Thanks ! 

RE: "isset" not working :-(


You should involve isset() only in logic to see whether a and b were actually sent to avoid you code crashing in their absence.

Given the empty form will be submitted as http://localhost/myIsset.php?a=&b=, var_export($_GET) will show :

CODE --> var_export($_GET)

array (
  'a' => '',
  'b' => '',
So $_GET['a'] being set, isset($_GET['a']) will evaluate to true.

The simplest in your case is to use ! empty($_GET['a']) instead.
Though things used to be more complex in practice : an isset($_GET['a']) based if controls whether a block with more detailed validations gets executed in case the parameter was received.


RE: "isset" not working :-(

Thanks a lot feherke.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close