...

View Full Version : testing for blank variables ?



jeddi
02-24-2008, 02:41 PM
Hello

I want to insert values only if the variables are not blank.

Is this the correct way to test it (in the if statement) ?



if(!$N_contact1 == "" && !$N_email1 == ""){

$sql = "INSERT INTO freinds (f_name, f_email, up_name, up_email, create_date)
VALUES ('$N_contact1','$N_email1','$N_contact','$N_email','$today')";

mysql_query($sql)
or die("could not execute CLIENT INSERT query");
} // end if


Thanks for any advice.

matak
02-24-2008, 02:44 PM
if($N_contact1 !== "" && $N_email1 !== ""){

rafiki
02-24-2008, 11:03 PM
if(!empty($N_contact1) && !empty($N_email1)) {
$sql = "INSERT INTO freinds (f_name, f_email, up_name, up_email, create_date)
VALUES ('$N_contact1','$N_email1','$N_contact','$N_email','$today')";

mysql_query($sql)
or die("could not execute CLIENT INSERT query");
} // end if


this?
www.php.net/empty

idalatob
02-25-2008, 09:03 AM
the trim issue with empty() gets me a little annoyed sometimes... what follows is what you need.


<?php
if (empty($var)){
echo("Empty");
} else {
echo("Full");
}
?>


hmmm, a little unrelated but does anyone know if you can run trim on a variable before using the empty statement?

jeddi
02-25-2008, 09:34 AM
Thanks for your replies.

Is there any difference in the results of:


1) if($N_contact1 !== "" && $N_email1 !== ""){

and

2) if(!empty($N_contact1) && !empty($N_email1)) {

???

Inigoesdr
02-25-2008, 02:15 PM
Thanks for your replies.

Is there any difference in the results of:


1) if($N_contact1 !== "" && $N_email1 !== ""){

and

2) if(!empty($N_contact1) && !empty($N_email1)) {

???

Yes, if someone enters (0, "0", null, false, array()) it will be considered empty() (http://php.net/empty), but not an empty string(!== "")



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum