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
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 10:32 am
I use the below code:
Code: Select all
<? $result = $_POSTїfunc]($_POSTїtext1]); ?>
<html>
<head>
<title>Generic Input Results</title>
</head>
<body>
<? echo "$result"; ?>
<p><a href="generic_form.html">Go again!</a></p>
</body>
</html>
And get the following Error:
Fatal error: Call to undefined function: () in c:\apache\htdocs\testing\display_input.php on line 1
I know it has something to do with :
Any ideas?
Last edited by
bironeb on Tue Mar 09, 2004 11:21 am, edited 1 time in total.
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue Mar 09, 2004 10:38 am
the point is that there is notthign set to $_POST[func] so its trying to call the fuction ($_POST[text1]) and you cant do that...so you need to decare it to be a function so do this:
Code: Select all
<?
if(isset($_POST[func]))
$result = $_POST[func]($_POST[text1]);
else
$result="no Function declared";
?>
<html>
<head>
<title>Generic Input Results</title>
</head>
<body>
<? echo "$result"; ?>
<p><a href="generic_form.html">Go again!</a></p>
</body>
</html>
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Tue Mar 09, 2004 10:40 am
yes it does... php probably thinks that you are trying to call a function with $_POST[func]($_POST[text1])..
what exactly are you trying to do with that line anyway?
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 10:42 am
Well i tried your idea:
Code: Select all
<? $result = $_POSTї'func'].$_POSTї'text1']; ?>
<html>
<head>
<title>Generic Input Results</title>
</head>
<body>
<? echo $result; ?>
<p><a href="generic_form.html">Go again!</a></p>
</body>
</html>
and now all it displays is the a href link
Go again!
but no error.
The following is the code from my html page:
Code: Select all
<html>
<head>
<title>Generic Input Form</title>
</head>
<body>
<FORM METHOD = "POST" ACTION = "display_input.php">
<p><strong>Text Field:</strong><br>
<TEXTAREA NAME="text1" COLS=45 ROWS=5 WRAP=virtual></TEXTAREA></p>
<p><strong>String Function:</strong><br>
<input type="radio" name="func" value="md5" checked> get md5<br>
<input type="radio" name="func" value="strlen"> get length of string<br>
<input type="radio" name="func" value="strrev"> reverse the string<br>
<input type="radio" name="func" value="strtoupper"> make string uppercase<br>
<input type="radio" name="func" value="strtolower"> make string lowercase<br>
<input type="radio" name="func" value="ucwords"> make first letter of all words uppercase</p>
<p><input type="submit" name="submit" value="Do Something With the String"></p>
</form>
</body>
</html>
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Mar 09, 2004 10:48 am
Code: Select all
<?php
$result = '';
if(!empty($_POST['func'])){
$result = $_POST['func']($_POST['text1']);
}
?>
<html>
<head>
<title>Generic Input Results</title>
</head>
<body>
<?php echo $result; ?>
<p><a href="generic_form.html">Go again!</a></p>
</body>
</html>
Be very careful with this code if it's on a public server, it wouldn't be difficult to post functions that you're not allowing for, exec, eval etc..
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 10:48 am
ok so now i tried:
Code: Select all
<?
if(isset($_POSTїfunc]))
$result = $_POSTїfunc]($_POSTїtext1]);
else
$result="no Function declared";
?>
<html>
<head>
<title>Generic Input Results</title>
</head>
<body>
<? echo $result; ?>
<p><a href="generic_form.html">Go again!</a></p>
</body>
</html>
And after i submit from the html page i get:
no Function declared
Go again![/url]
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 10:54 am
Ok tried the 3rd suggestion:
Code: Select all
<?php
$result = '';
if(!empty($_POSTї'func'])){
$result = $_POSTї'func']($_POSTї'text1']);
}
?>
<html>
<head>
<title>Generic Input Results</title>
</head>
<body>
<?php echo $result; ?>
<p><a href="generic_form.html">Go again!</a></p>
</body>
</html>
and it only displayes:
Go again!
hmmm, any other ideas?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Mar 09, 2004 10:55 am
It works fine for me. Are you pressing 'enter' to submit the form or pressing the button? Also double check your html, the below html form worked ok with the above php code.
Code: Select all
<html>
<head>
<title>Generic Input Form</title>
</head>
<body>
<FORM METHOD = "POST" ACTION = "display_input.php">
<p><strong>Text Field:</strong><br>
<TEXTAREA NAME="text1" COLS=45 ROWS=5 WRAP=virtual></TEXTAREA></p>
<p><strong>String Function:</strong><br>
<input type="radio" name="func" value="md5" checked> get md5<br>
<input type="radio" name="func" value="strlen"> get length of string<br>
<input type="radio" name="func" value="strrev"> reverse the string<br>
<input type="radio" name="func" value="strtoupper"> make string uppercase<br>
<input type="radio" name="func" value="strtolower"> make string lowercase<br>
<input type="radio" name="func" value="ucwords"> make first letter of all words uppercase</p>
<p><input type="submit" name="submit" value="Do Something With the String"></p>
</form>
</body>
</html>
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 10:59 am
I tried both ways, Pressing ENTER after i choose radial, and clicking the button... but it only displays the URL the $result isn't printing, im confused.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Mar 09, 2004 11:01 am
Is this online somewhere we can see it running?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Mar 09, 2004 11:04 am
What version of PHP? If it's => 4.1.0 then repost the exact code you have now, if it's less than 4.1.0 then don't bother, it won't work
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 11:06 am
well i go to:
http://127.0.0.1/phpinfo.php
and it says:
PHP Version 4.0.5
Is this my problem? if so why? and how would I upgrade?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue Mar 09, 2004 11:07 am
Yeah, that's the problem. $_POST didn't come into existance until 4.1.0.
Just goto
http://php.net and download the latest stable version, installation/upgrade instructions will be in the file you download. What OS are you on by the way (windows, *nix, etc..) ?
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Tue Mar 09, 2004 11:09 am
Thanks markl999 I'll upgrade and try again. I'm using Windows XP btw.