call php function

Posted on 2012-08-15
Last Modified: 2012-08-16
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">
Question by:cnermin
    LVL 17

    Accepted 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 :
    LVL 36

    Expert Comment

    by:Loganathan Natarajan
    Yes, you can achieve this using AJAX functions,  simple example

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now