-1

I have a simple web application. There is an input form where I can enter script tag (HTML too but not PHP). The goal is to modify the SQL database.

Can I execute PHP functions on the server side with client side javascript?

  • You can call the backend (PHP) from javascript using Ajax. Without more info, that's about as specific I can get. – M. Eriksson Feb 26 '21 at 09:28
  • 1
    You should probably have a thorough read of [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) first of all, because it sounds like you are lacking a bit of basic knowledge here. – CBroe Feb 26 '21 at 10:09

1 Answers1

0

No, you can't execute PHP using JS, but using JS, you can call PHP script with required arguments, which will do what you need. If yo want to do it without site reload, use AJAX to run the call in background.

The keywords here are: client-side and server-side.

Bit longer:

JS is client-side and everything it does, is made on your computer, PHP is server-side so all tasks are executed on server (even if it's local machine). In this scenario, to run any PHP script from client-side JS (or even HTML) you need to send a request to server-side PHP, and then handle its response somehow.

biesior
  • 55,576
  • 10
  • 125
  • 182