Jump to content

field from database table row is empty but php doesnt recognise it


JKG

Recommended Posts

anyone know why this wouldn't work?

 

function tws_empty($var, $type){
if(!empty($var) and ($var != '')){
	//type 1: profile page address
	if($type == 1){
		echo $var . ', <br />';
	}	
}
}

 

the field from the row is definitely empty, but i cant get it to show as empty...

 

even a simply line like:

 

if(empty($displayUser['address_2'])){echo 'asdf';};

 

just isnt echoing...

 

any thoughts? i know its something really simple!!

thanks.

Joe.

thank you for your help with this.

 

i have now updated my function to:

 

function tws_empty($var, $type){
if(!empty($var) && ($var != '') && ($var != ' ')){
	//type 1: profile page address
	if($type == 1){
		echo $var . ', <br />';
	}	
}
}

 

i thought empty() took whitespace into account...

 

ord() displays nothing... with or without the space...

that sounds more efficient, however i get this error:

 

Fatal error: Can't use function return value in write context in /home/theweddi/public_html/scripts/functions.php on line 270

 

even when im not calling the function.

 

any ideas?

Where is the data value in the table originally coming from? Given that the field is named - address_2, this is likely a second line of their address from a form field or from a csv data import. You are expecting it to be empty, but it clearly is not. You need to filter/trim it before it gets inserted and/or you need to find what is causing it to be non-empty but not an actual usable value to be displayed in the first place.

 

 

i trimmed the values before and now it works fine.

 

the function is just to display the various fields, but some are optional, and i didnt want to but a line break and comma there for users who have not entered their details. it was a simple idea but just took me longer due to my lack of proper debugging.

 

so thank you PFMaBiSmAd and TeNDoLLA.

 

ord returned 32 - it has a space character in it...

 

to my mind this is solved now, thanks for all your help. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.