Page 1 of 1
can a user call a function
Posted: Tue Sep 02, 2003 4:49 pm
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!!
Posted: Tue Sep 02, 2003 5:09 pm
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']);}
Posted: Tue Sep 02, 2003 5:35 pm
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.
Posted: Tue Sep 02, 2003 5:49 pm
by yarrgh
i cant' find any documentation for "$user_properties" what is it and how do i use it?
Posted: Tue Sep 02, 2003 5:53 pm
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
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.