Jump to content

Calling PHP functions


ekuemoah

Recommended Posts

I created a script on a php page. The script is activated when user clicks the submit button on a form. I want to write functions on the same php page. How do I do this? MyData.php<?function getData(){$fname = _POST['fname']; $lname = _POST['lname']; //statements that tells it to write the information to file} function showData(){$price = _POST['price']; $qty = _POST['qty']; $total = $price * $qty; echo $total;}?> MyOutputPage.php<html><head><title>Sample Page</title></head><body>//I want to call the showData() function on the MyData.php page.//How do I do this? <form action=" " method="post"><input type="submit" value="Submit"/></form></body></html> Once I do this, how do I call individual functions on the page. Is there a way to add it to my page with the html like you do when linking to an external javascript script? Thank You

Link to comment
Share on other sites

first, do you understand that PHP runs before the page has loaded? Everything you want it to do needs to be accounted for in that way. A common technique is to have javascript make AJAX requests to a server side script, by passing it some data, and then that script executes the code.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...