Page 1 of 2
SOLVED: Need Help with string modification script.
Posted: Tue Mar 09, 2004 10:32 am
by bironeb
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?
Posted: Tue Mar 09, 2004 10:38 am
by PrObLeM
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>
Posted: Tue Mar 09, 2004 10:40 am
by liljester
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?
Posted: Tue Mar 09, 2004 10:42 am
by bironeb
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>
Posted: Tue Mar 09, 2004 10:48 am
by markl999
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..
Posted: Tue Mar 09, 2004 10:48 am
by bironeb
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]
Posted: Tue Mar 09, 2004 10:54 am
by bironeb
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?
Posted: Tue Mar 09, 2004 10:55 am
by markl999
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>
Posted: Tue Mar 09, 2004 10:59 am
by bironeb
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.
Posted: Tue Mar 09, 2004 11:01 am
by markl999
Is this online somewhere we can see it running?
Posted: Tue Mar 09, 2004 11:03 am
by bironeb
No, sorry its running on the apache server on my computer only... I hit it by going to:
http://127.0.0.1/testing/generic_form.html
Posted: Tue Mar 09, 2004 11:04 am
by markl999
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

Posted: Tue Mar 09, 2004 11:06 am
by bironeb
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?
Posted: Tue Mar 09, 2004 11:07 am
by markl999
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..) ?
Posted: Tue Mar 09, 2004 11:09 am
by bironeb
Thanks markl999 I'll upgrade and try again. I'm using Windows XP btw.