By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

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

dnb
P: 34
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_connect('phptest1','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$ename ="Hello";
$eno=23;
$sql = "insert into edetail(eno,ename) values('$eno','$ename')";
$rs=odbc_exec($conn,$sql);
odbc_close($conn);
}
?>[/PHP]

Plz Help Me.
Thanx In Advance........
Feb 27 '08 #1
Share this Question
Share on Google+
8 Replies


Markus
Expert 5K+
P: 6,050
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_connect('phptest1','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$ename ="Hello";
$eno=23;
$sql = "insert into edetail(eno,ename) values('$eno','$ename')";
$rs=odbc_exec($conn,$sql);
odbc_close($conn);
}
?>[/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!
Feb 27 '08 #2

hsriat
Expert 100+
P: 1,654
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_connect('phptest1','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$ename ="Hello";
$eno=23;
$sql = "insert into edetail(eno,ename) values('$eno','$ename')";
$rs=odbc_exec($conn,$sql);
odbc_close($conn);
}
?>[/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?
Feb 27 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
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:
Expand|Select|Wrap|Line Numbers
  1.     if form is POSTed {
  2.         assign POST vars to PHP variables
  3.         prepare SQL INSERT statement
  4.         execute INSERT statement    
  5. }
  6. display form 
  7. on onClick: call submitit function  
  8.  
  9. javascript 
  10.      function: submitit() {
  11.         submit form
  12.      }                 
Ronald
Feb 27 '08 #4

dnb
P: 34
dnb
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..................
Feb 29 '08 #5

hsriat
Expert 100+
P: 1,654
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.
Feb 29 '08 #6

P: 11
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
Mar 1 '08 #7

P: 2

P: 30
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()
Apr 27 '11 #9

Post your reply

Sign in to post your reply or Sign up for a free account.