I am trying to figure out the correct syntax to check if a variable if not null. There are 2 variables that may or may not have a value. If the first variable is not null, then I want to execute a mysql query, otherwise I want to check to see if the second variable is not null. I keep getting an error - unexpected T_IS_NOT_EQUAL .

Here is the code snip:

...

$in_lname = $_POST["l_name"];
$in_f_name = $_POST["f_name"];
$in_city = $_POST["city"];
$in_state = $_POST["state"];

?>
</select><p><p>
<input name="submit" value="Submit" type="submit">
</form>
<?php
//connect to database

  $link = mysql_pconnect('localhost', 'xxxxx, 'xxxxx');
if (!$link) {die('Could not connect: ' . mysql_error());}
mysql_select_db("xxx", $link);

[COLOR="Red"]if ($in_lname) <> " "[/COLOR]

  $get_member_sql = "SELECT mbr_id, f_name, l_name from member_name where l_name like '%$in_lname%'";
  $get_member_res = mysql_query($get_member_sql, $link)
			   or die(mysql_error());

[COLOR="Red"]else if ($in_fname) <> " "[/COLOR]

  $get_member_sql = "SELECT mbr_id, f_name, l_name from member_name where f_name like '%$in_fname%'";
  $get_member_res = mysql_query($get_member_sql, $link)
			   or die(mysql_error());

else exit; 

...

    The syntax error is due to misplaced closing parentheses.

    if ($in_lname) <> " "
    

    ...should be...

    if ($in_lname <> " ")
    

    Note however that your are comparing the variable to a string literal of one space, which may not be what you want. Possibly a better test, depending on the actual data and desired logic, would be:

    if (trim($in_lname) !== "")
    

    (Note the use of the "not identical" !== operator, and that I removed the space between the quotes since I'm trim()-ing the variable that is being compared.)

      also error here:

      <?php
      $link = mysql_pconnect('localhost', 'xxxxx, 'xxxxx'); 
      //should be
      $link = mysql_pconnect('localhost', 'xxxxx', 'xxxxx'); 
      ?>
      

        Thank you. if (trim($in_lname) !== "") is working well!

          Write a Reply...