Sign in to follow this  

[web] Newbie PHP problem

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
<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>Calculation:<br>
<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>

</FORM>

</BODY>
</HTML>



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

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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