Sign in to follow this  

[web] Newbie PHP problem

Recommended Posts

Alright, I’m new to php and general html. I am following a php book right now and I am at a section where I should be using the calculate.php script to handle a form. The problem is that the val1 value for the field isn’t being passed to the script. Why isn’t this happening? This I my html file
<TITLE>Calculation Form</TITLE>

<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>

<INPUT TYPE="radio" NAME="calc" VALUE="add"> add<br>
<INPUT TYPE="radio" NAME="calc" VALUE="subtract"> subtract<br>
<INPUT TYPE="radio" NAME="calc" VALUE="multiply"> multiply<br>
<INPUT TYPE="radio" NAME="calc" VALUE="divide"> divide</p>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Calculate"></p>



This is my php scipt file, calculate.php

echo "<p>val1: $val1</p>";


When I enter values into this(say 3 and 4) and press submit, I just get a web page with the following: Val1:

Share this post

Link to post
Share on other sites
in older versions of PHP, any value passed to the script through the URL or using POST, was automatically created as a global variable. Your book seems to be using the older versions of PHP, and assumes globals is on.

Newer versions of PHP have globals disabled, as its a potential security threat.

To access the data from the form, you should use $var = $_GET["var1"] or $var = $_POST["var1"] depending on whether the form was set to POST or GET.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this