September 23, 2012

Syntax error on trying to update empty column row values

Question by Woistmeinhandy

I am trying to add a keyword to empty column / row values in my database but I can’t get it to work. I am getting a syntax error.

Here is the code:

$sql[$handle]['sql'] = 
'SELECT IF(char_length('.$field.')>0, '.$field.',''.$replace.'') AS '.$field.' 
FROM '.$table.'')';

Answer by Starx

You have escaped a quote extra on the end.

$sql[$handle]['sql'] = 
'SELECT IF(char_length('.$field.')>0, '.$field.',''.$replace.'') AS '.$field.' 
FROM '.$table.'')';
//              ^ Right here

Next, you have an extra bracket ) at the end [Credit: Registered User]

$sql[$handle]['sql'] = 
'SELECT IF(char_length('.$field.')>0, '.$field.',''.$replace.'') AS '.$field.' 
FROM '.$table.')';
//             ^ Right here

Solution: Remove them and you should get something like this to work:

$sql[$handle]['sql'] = 'SELECT IF(char_length('.$field.')>0, '.$field.',''.$replace.'') AS '.$field.' FROM '.$table;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!