Jump to content

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


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.

It's a string consisting of 1 (one) white-space character. It's either a space, a tab, or it could even be a new-line.

 

What does the following show -

 

ord($displayUser['address_2']);

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. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.