-2

I am trying to call a shortcode when clicking on a button. That short code updates mysql colum. Below the code I have is not working. When clicked all it does is simple add /"" to my web address without running the shortcode.

 <div class="seat-btn"><a href="<?php my_custom_shortcode(); ?>"   > CLICK TO OPEN SHORTCODE</a></div>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Manny
  • 3
  • 5
  • Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Dharman Sep 13 '20 at 11:35
  • No thank you though. I did know that. Some other "solution" on Stackover flow indicated the above worked. – Manny Sep 13 '20 at 18:13

1 Answers1

1

You can't execute php code in the front-end like this. PHP is a server side language. The suggested approach for your request is to use Javascript to execute that short code, or to make a Get request to php page to execute that code at server side.

zaher.si
  • 24
  • 4
  • 1
    ah thanks. I got this off another stackover flow article that had this as the solution. It didnt seem right to me. Is there a security risk in have JS call a .php file that everyone then knows the name of? – Manny Sep 13 '20 at 04:11
  • 1
    In general you should not expose sensitive information in Get requests or in Javascript code, I found this information for REST API Security essentials, I think it could be helpful: https://restfulapi.net/security-essentials/ – zaher.si Sep 13 '20 at 04:21