can a user call a 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
yarrgh
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2003 4:49 pm

can a user call a function

Post by yarrgh »

i am new to php, and have searched hours for the answer to this.

what i need is for there to be several functions waiting on the php page, and for the user to be able to call any of those functoins. it seems like there should be a way for form buttons to call specific functions. thanks to any help!!
Aaron
Forum Commoner
Posts: 82
Joined: Sun May 12, 2002 2:51 pm

Post by Aaron »

Code: Select all

if($user_properties['status'] == 'admin')
{function($user_properties['uid']);}
elseif($user_properties['status'] == 'mod')
{function2($user_properties['uid']);}
else
{function3($user_properties['uid']);}
yarrgh
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2003 4:49 pm

Post by yarrgh »

whoa... whats the blue and red mean? im not understanding that snippet there. i think i need a little explaination to go along with it.
yarrgh
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2003 4:49 pm

Post by yarrgh »

i cant' find any documentation for "$user_properties" what is it and how do i use it?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please read Sticky: Before Post Read: Frames, JavaScript, and PHP Overview
then try

Code: Select all

<html>
	<head>
		<title>function test</title>
	</head>
	<body>
<?php
function add($a,$b) { return $a+$b; }
function sub($a,$b) { return $a-$b; }
function mul($a,$b) { return $a*$b; }
function div($a,$b) { return $a/$b; }

if (isset($_POST['action']))
{
	if(in_array($_POST['action'], array('add','sub','mul','div')))
		echo call_user_func($_POST['action'], 4, 2), '<hr />';
}
?>
		<table>
			<tr>
				<td>4</td>
				<td>
					<form method="post">
						<input type="submit" name="action" value="add"/><br />
						<input type="submit" name="action" value="sub"/><br />
						<input type="submit" name="action" value="mul"/><br />
						<input type="submit" name="action" value="div"/><br />
					</form>
				</td>
				<td>2</td>
			</tr>
		</table>
	</body>
</html>
The colors are set by the syntax-highlighter when you put php code in

Code: Select all

...
tags here
$user_properties is just a variable.
Guess you should start at http://www.php.net/docs.php and then go on with a php-tutorial.
Post Reply