Jump to content
  • Advertisement
Sign in to follow this  

[web] Newbie PHP problem

This topic is 4581 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
<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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!