You can’t execute php code inside the standard text widget. That is why this is not working for you.
If you don’t feel up to creating your own widget to handle this, you could probably use a plugin like:
https://wordpress.org/plugins/php-code-widget/
I don’t have experience with this type of plugin, but it would be a quick fix. Just be aware of the security considerations mentioned in the plugin’s description.
Hope this helps!
Brad
Thanks a lot bradchando. It is now working perfectly.
Nobody else, except me, has the access to my website, so I don’t think there would be any security threat.
Thanks again. I had wasted a lot of time on this.