[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 684
  • Last Modified:

call php function

when I have two buttons and one needs to call php function I have a problem.
I tried over jscrip, php, "action", "onclick", etc but not working. If I use <a hrf = "createDB" then I have a problem when it opens the start page, then the function is executed without someone Clik

include './include/baza.php';
  function createDB(){
  $query  = 'CREATE DATABASE db_'.$_GET["idbr"] ;
   $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
 return 'baza je uspjesno kreirana ';
 <textarea rows="1" cols="40" name="content"><?php echo  $fn?></textarea><br><br>
 <div> <input type="button" onclick=" createDB()" value="Create DB" > > </div>

<form action="<?php echo  "onlin.php"?>" method="post">
   <input type="submit" value="POVRATAK NAZAD">
1 Solution
You need to use jquery ajax to call createDB function as it is server side function.

1. Create php file (say createdb.php) add the createDB in that file
2. change to <input type="button" onclick=" createDB()" value="Create DB" id="createdb" >
3. Add below script to your main page

  type: "POST",
  url: "createdb.php"// path to your file

}).done(function( msg ) {
  alert( msg );


More information : http://api.jquery.com/jQuery.ajax/
Loganathan NatarajanLAMP DeveloperCommented:
Yes, you can achieve this using AJAX functions,  simple example

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now