Call php function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alicefreak
Forum Newbie
Posts: 2
Joined: Mon Sep 13, 2010 11:40 am

Call php function

Post by alicefreak »

Hello guys, I'm new to PHP. Please help me. I have two functions in myFunctions.php
1 is myName() and second one is yourName()

Code: Select all

function myName()
{
      echo "my name is this.";
}
function yourName()
{
    echo "your name is that.";
}
and I have two submit button. One is my and another is you. When user click on my button. then myName() function is called and when user click on you then yourName() function is called.
Please help me. Thanks
User avatar
bradbury
Forum Commoner
Posts: 40
Joined: Wed Aug 25, 2010 11:21 am
Location: Eugene, OR

Re: Call php function

Post by bradbury »

put this in a separate php document (linkto.php) in this example

Code: Select all

fucntion myName($name) {
$name = $_POST['name'];
echo $name;
}
HTML
------
<form name="whatever" method="post" action"linkto.php">
<input type="text" name="name"id="name">
<input type="submit" name="Submit" value="Whatever you want displayed">

Hope this makes sense and you can apply this to your other function
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Call php function

Post by AbraCadaver »

You can get fancier, but in general:

Code: Select all

<form method="post">
<input type="submit" name="submit" value="my">
<input type="submit" name="submit" value="you">
</form>
		
<?php

if(isset($_POST['submit'])) {
	switch($_POST['submit']) {
		case 'my':
			myName();
			break;
			
		case 'you':
			yourName();
			break;
	}
}
			
function myName()
{
      echo "my name is this.";
}
function yourName()
{
    echo "your name is that.";
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Call php function

Post by califdon »

alicefreak wrote:Hello guys, I'm new to PHP. Please help me. I have two functions in myFunctions.php
1 is myName() and second one is yourName()

Code: Select all

function myName()
{
      echo "my name is this.";
}
function yourName()
{
    echo "your name is that.";
}
and I have two submit button. One is my and another is you. When user click on my button. then myName() function is called and when user click on you then yourName() function is called.
Please help me. Thanks
Separate in your mind the concepts of a form and a function. They are two unrelated parts of PHP. All a function does is return a value to somewhere else in the same script that calls the function. A form is the "wrapper" for a bunch of data input elements and when its submit button is clicked, it sends data to another script (or itself, if you put the right logic into it), so that it can recover the form data from either the $_POST or $_GET global array, as specified in the form tag. Don't get forms confused with functions.
alicefreak
Forum Newbie
Posts: 2
Joined: Mon Sep 13, 2010 11:40 am

Re: Call php function

Post by alicefreak »

thanks for my help. :D
Post Reply