$query="INSERT INTO subscriber (RandomCode,Email,CreateDate,UpdateDate <?if ($num!=0) echo ','.$string; ?> ) VALUES (?,?,?,?,CURDATE(),'',<? if ($num!=0) echo ','.$stringResult; ?>)";
echo $query;
If i add something conditional in the sql statement , it will not check or trigger the php function.
if (!isset($set['Attribute']))
{$set['Attribute']=NULL;} <=======This statement to check if there is no value posted
$stringResult=$stringResult.$_POST[$set['Attribute']].",";}}
$stringResult = substr($stringResult, 0, -1);
echo $stringResult;
Also, if a result is a null value posted, how can i set it so that it can be view in stringResult as ” ? I need to put it in my sql statement.
Thank you.
This is broken; you don’t echo to add to a string, you need to concatenate it together. Here’s how:
When you are guilding a string and need to stop and make a decision, like “is this zero? then do this, now continue on.”, you need to end the string, concatenate a string into it if need be, and then concatenate the rest of the string onto the end. Continue ending the string and concatenating parts on until you are done.
If you are adding a null value to a string, it’s the same as adding an empty string –
''.The resulting string is exactly the same. While NULL !== “” (meaning NULL and “” are not identical because they are not the same type), as far as the resulting string goes, it’s the same.