Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Problem with getting avriables from forms

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Problem with getting avriables from forms

Postby ylkien » Sat Dec 14, 2002 9:56 am

Hi, i'll keep it short. i am trying to create a simple calculator. 2 files. (1 is html & the other is php). This is my caculator_form.html file's code :

<html>
<head>
<title>Calculation Form</title>
</head>

<body>

<form method="post" action="calculate.php">

<p>Value 1 : <input type="text" name="val1" size=10></p>
<p>Value 2 : <input type="text" name="val2" size=10></p>

<p>Type of calculation: <br>
<input type ="radio" name ="calc" value = "add">add<br>
<input type ="radio" name ="calc" value = "subtract">sub<br>
<input type ="radio" name ="calc" value = "multiply">multiply<BR>
<input type ="radio" name ="calc" value = "divide">divide<BR></p>


<input type="submit" name="submit" value="Calculate">

</form>

</body>
</html>


This is my second file file, calculator.php :

<html>
<head>
<title> calculation result</title>
</head>
<body>


<? if ($val1 == NULL || $val2 == NULL || $calc == NULL)
{ echo "<p>ERROR!!!!</p>"; }


if ($calc == "add") {
$result = $val1 + $val2;
}

else if ($calc == "subtract") {
$result = $val1 - $val2;
}

else if ($calc == "multiply") {
$result = $val1 * $val2;
}

else if ($calc == "divide") {
$result = $val1 / $val2;
}

?>

<? echo "<p>The result of the calculation = $result </p>"; ?>

</body>
</html>


i don't see any problem with this code. Futher more, it is from a php book which i am currently studying. I am unable to pass the values "val1" & "val2" from the html to the php file. What could the problem be? Could it be my configuration for php isn't correct? Thanks.
ylkien
New php-forum User
New php-forum User
 
Posts: 28
Joined: Sat Dec 14, 2002 9:43 am

Postby webwired » Sat Dec 14, 2002 4:53 pm

Make sure that your register_globals = On...
User avatar
webwired
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Nov 23, 2002 5:20 pm
Location: St. Louis, Missouri

Postby ylkien » Sun Dec 15, 2002 10:28 am

ok, i have another problem. The "$func" doesn't get passed. Which of the php config do i have to change?

These are the codes that i am working on :

This is the file "generic_form.html" :

<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" > lowercase<BR>
<input type = "radio" name = "func" value = "ucwords" > make first letter of all words uppercase<BR>

</p>

<p><Input type = "submit" name = "submit" value = "do something with the string"></p>

</form>
</body>
</html>


This is the file "display_input.php" :

<? $result = $func($text1); ?>

<html>
<head>
<title>Generic input results</title>
</head>
<body>

<? echo " $text1 & $results"; ?>

<p><a href="generic_form.html">Go again!!</a></p>

</body>
</html>
ylkien
New php-forum User
New php-forum User
 
Posts: 28
Joined: Sat Dec 14, 2002 9:43 am

Postby webwired » Sun Dec 15, 2002 10:15 pm

Code: Select all
<? echo " $text1 & $results"; ?>

should be
Code: Select all
<? echo " $text1 & $result"; ?>
User avatar
webwired
New php-forum User
New php-forum User
 
Posts: 26
Joined: Sat Nov 23, 2002 5:20 pm
Location: St. Louis, Missouri

Postby ylkien » Wed Dec 18, 2002 10:35 am

thanks!!
ylkien
New php-forum User
New php-forum User
 
Posts: 28
Joined: Sat Dec 14, 2002 9:43 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.