Invoke JavaScript function using "onclick" in php -


this question has answer here:

on clicking text, js function should executed.

in html:

<html> <body> <a href="#" onclick="clickthis();">table 1</a> </body> </html> 

in php:

<?php require 'dbconnect.php';  function clickthis(){ $search_table = "select `table1` `booktable` `table1`='booked';" $query = mysqli_query($dbconnect,$search_table);   if(mysqli_num_rows($query)==0){   "insert `booktable` (table1`) values(`booked`)";   echo'table booked successfully.'; ?> 


have placed onclick function correctly in html?
whenever click on text table 1, clickthis() function should executed how can achieve result using php, javascript & html.

p.s. i don't want use button click & dbconnect.php external php file.

you need execute php script through ajax call. way approaching structure wrong.

you can take following steps.

  1. create php script , serve on /booktable
  2. have js script fetch above url through ajax call.
  3. bind js function onclick in html markup.

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -