call a php function on a onclick event of html submit button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dnb
    New Member
    • Jan 2008
    • 34

    call a php function on a onclick event of html submit button

    Hi Friends,

    i learn a phpso plz help me.
    i want to call a php fundtion on a onclick event of html submit button
    this function is work properly but i don't know how to call it on a onclick event of html submit button..


    [PHP]<?php
    function adddata()
    {
    $conn=odbc_conn ect('phptest1', '','');
    if (!$conn)
    {exit("Connecti on Failed: " . $conn);}
    $ename ="Hello";
    $eno=23;
    $sql = "insert into edetail(eno,ena me) values('$eno',' $ename')";
    $rs=odbc_exec($ conn,$sql);
    odbc_close($con n);
    }
    ?>[/PHP]

    Plz Help Me.
    Thanx In Advance........
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by dnb
    Hi Friends,

    i learn a phpso plz help me.
    i want to call a php fundtion on a onclick event of html submit button
    this function is work properly but i don't know how to call it on a onclick event of html submit button..


    [PHP]<?php
    function adddata()
    {
    $conn=odbc_conn ect('phptest1', '','');
    if (!$conn)
    {exit("Connecti on Failed: " . $conn);}
    $ename ="Hello";
    $eno=23;
    $sql = "insert into edetail(eno,ena me) values('$eno',' $ename')";
    $rs=odbc_exec($ conn,$sql);
    odbc_close($con n);
    }
    ?>[/PHP]

    Plz Help Me.
    Thanx In Advance........
    In simple, non-ajaxogical, terms - it's impossible.
    Serverside is serverside and definitely not clientside (javascript - onclick).

    However, if you were to use ajax, you could indeed call this function through the onclick of an submit button.
    check this good tutorial out

    When you've given it a shot, post back with the code!

    Comment

    • hsriat
      Recognized Expert Top Contributor
      • Jan 2008
      • 1653

      #3
      Originally posted by dnb
      Hi Friends,

      i learn a phpso plz help me.
      i want to call a php fundtion on a onclick event of html submit button
      this function is work properly but i don't know how to call it on a onclick event of html submit button..


      [PHP]<?php
      function adddata()
      {
      $conn=odbc_conn ect('phptest1', '','');
      if (!$conn)
      {exit("Connecti on Failed: " . $conn);}
      $ename ="Hello";
      $eno=23;
      $sql = "insert into edetail(eno,ena me) values('$eno',' $ename')";
      $rs=odbc_exec($ conn,$sql);
      odbc_close($con n);
      }
      ?>[/PHP]

      Plz Help Me.
      Thanx In Advance........
      Didn't you try calling this function in that particular PHP file whom you set as value of action attribute in the form tag?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        It could be that I completely misunderstand the question. Maybe that is me or the way the problem is stated. So let me ask:
        Do you really want to execute a PHP function or do you just want to fill in a form, submit on onClick and then insert the form fields into the database? If the latter is the case, your script would look like:
        Code:
            if form is POSTed {
                assign POST vars to PHP variables
                prepare SQL INSERT statement
        	    execute INSERT statement	
        }
        display form 
        on onClick: call submitit function  
        
        javascript 
             function: submitit() {
                submit form
             }
        Ronald

        Comment

        • dnb
          New Member
          • Jan 2008
          • 34

          #5
          Originally posted by hsriat
          Didn't you try calling this function in that particular PHP file whom you set as value of action attribute in the form tag?

          Hi....
          i try my best to call this php function but it not works...
          plz say me how can i call this php function?

          plz help me............. .....

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by dnb
            Hi....
            i try my best to call this php function but it not works...
            plz say me how can i call this php function?

            plz help me............. .....
            • Modify your function so that it can accept arguments.
            • Call this function using the $_POST[ ] variables as the arguments of this function.

            Comment

            • eddierosenthal
              New Member
              • Jan 2008
              • 11

              #7
              Originally posted by dnb
              Hi....
              i try my best to call this php function but it not works...
              plz say me how can i call this php function?

              plz help me............. .....
              when you say it doesn't work is there an error message? At what point in the program does it fail? There was a suggestion of using a call from the 'action' of the form - are you using that or are you supplying an onclick event to the submit button - i don''t think you need to do that unless you are trying to apply multiple events? in that case you probably would have to addlistener events to a button object in javascript.
              if you have parts of the form ( input text areas , checkboxes) then you can create onclick events and send the values to a php function thru a html object ( ajax processing), which is the easiest way to accomplish something from html/javascript to php.
              hth

              Comment

              • Ivan Carrasco Q
                New Member
                • Apr 2011
                • 2

                #8


                This topic may help you!
                :-)

                Comment

                • Rekha Kumaran
                  New Member
                  • Jan 2011
                  • 30

                  #9
                  Read about FORM....

                  1)In HTML program, use form and redirect to ur PHP program.
                  2) Use GET or POST, get the values from the HTML program.
                  3) Check whether if it is click or not and call the function adddata()

                  Comment

                  Working...