You're mixing inline AMPscript notation in an AMPscript block. That won't work.
But, you don't need the AMPScript block in your email at all since the CloudPagesURL() function will handle everything. It encrypts and passes along the send context (the profile attributes, sending data extensions column values, etc., for the subscriber) to the Cloud Page.
If you need just the total rowcount of your dataextension, you can utilize DataExtensionRowCount()
In which case you just:
set @neededNumber = DataExtensionRowCount('TableName')
This is optimal as Lookups cap out at around 2500 and are much heavier with processing creating longer and unnecessary time sucks. This is because the lookups will pull all the ...
Your client side click handler will not be able to call the server side function. The SSJS block will run independently when the page is being rendered by the server, and client browsers will not be able to call it.
To make this work, I would setup a second page where every request to it is logged, perhaps with added values passed to the page as parms.
You need to remove the @ sign from the variable in your SSJS code. The line should be:
You should also make sure the ampscript variable exists prior to setting the value.
Smart Capture indeed does not support Update / Upsert.
Without Smart capture (but a custom coded form / handler setup), UpsertDE() AMPScript function is a simple workaround.
If Smart Capture is indeed a requirement, then UpsertDE function won't help because there is no possibility for a handler page with Smart Capture.
In this case, you have to work with ...