1 button; different external urls 'associated with product_name' on page

Hi people,

Im wondering the possibilitys of PhP. Maybe im forsing the possibilitys a little. Here i want to explain what im trying to do.

There is a classic page in PhP. You can see the picture of the page, the name, the price, etc. You have also a ‘add to cart’ button. I want to make a second button with a external url. But my PhP code needs to choose the right url associated with the product_name on the page. Im working on this version now:

As you can see there i have 2 problems.
1. how to import that [product_name] and make that the input element
2. how to send the output to the onclick function of the html button

At least, the same php product page is showing me maybe product thee and showing you product coffie… if a click on the button i get a different external URL than you.

It will be wonderfull if some people can show me some solutions.

Thank you all