-5

Is it possible to call a function without javascript/Jquery/Ajax in one PHP file.

<?php

$connect = mysqli_connect("localhost","root","","");

<a href="#" onclick="permit_access()">Permit</a>

function permit_access() {
  $permit = mysqli_query($connect,"UPDATE permittable SET confirm = 1 WHERE id = keyid");
  return $permit;
}

?>
Sagasun
  • 15
  • 6
  • 1
    If you want to call a php function with onClick you can't. Please explain better what do you want to do – Sfili_81 Feb 11 '20 at 11:17
  • Not only with onclick, something id="permit_access();" – Sagasun Feb 11 '20 at 11:18
  • 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) – Nico Haase Feb 11 '20 at 13:53

1 Answers1

3

This is not possible.

I would recommend you read about "server side scripts" and "client side scripts".

They live on different planets. :)

Mark
  • 1,852
  • 3
  • 18
  • 31
  • @Sagasun Exactly, Yemil is totally right! You cannot bind click events which are run on the client side to execute some PHP code which is running on the server side without having a request to the server. Your server returns a page to the browser and then stops executing and doesn't handle the events in the browser. The click event handled in JS in the browser has to initiate an Ajax call to the server or call an action on the server by reloading the page with some query parameters to tell the PHP engine what to do. – Patrick Janser Feb 11 '20 at 11:23
  • Thank You Patrick Janser. I agree. I just wanted to clearly confirm either can be implemented without client-side. I'm afraid why the question has -4 votes. – Sagasun Feb 11 '20 at 11:27