Help - Search - Members - Calendar
Full Version: PHP Form question
HTMLHelp Forums > Programming > Server-side Scripting
thomas
How do I write an If/then statement in PHP for the following:

I want one variable to equal a numeric value IF another variable has a particular string for a value.

Basically, I want to convert qualitative data selected using radio buttons to be converted into quantitative data. However, I need the immediate values identified in the radio button command to be the qualitative strings. Therefore, I figured I would create two variables for each section, which would allow for the conversion if I can get the code right. I then want to add up all the values of the second variables to produce an overall score.

Something along the lines of:

If $value1="My name is Tom" Then $value2="2"

Also,the form script and handling script are separate files. In light of this, is it better to write the If/Then statement in the form code or handle code.

Any help would be appreciated.

Thanks.
Brian Chandler
QUOTE(thomas @ Oct 10 2006, 12:08 AM) *

How do I write an If/then statement in PHP for the following:

I want one variable to equal a numeric value IF another variable has a particular string for a value.

Basically, I want to convert qualitative data selected using radio buttons to be converted into quantitative data. However, I need the immediate values identified in the radio button command to be the qualitative strings. Therefore, I figured I would create two variables for each section, which would allow for the conversion if I can get the code right. I then want to add up all the values of the second variables to produce an overall score.

Something along the lines of:

If $value1="My name is Tom" Then $value2="2"


http://www.php.net/manual/en/language.cont...l-structures.if

QUOTE


Also,the form script and handling script are separate files. In light of this, is it better to write the If/Then statement in the form code or handle code.


Well, where is this decision made? If on the basis of how the user responds to the form, it can hardly be made as you generate the form, can it?

When you have written this if(...), what is your script going to do? Perhaps your script responding to the form might be something like:

if($_POST['answer'] == 'Tom')
echo "<p>You got my name right!";
else
echo "<p>Sorry, no, ", $_POST['answer'], " is not my name!";

But you also have to learn how to access the values submitted in the form ($_POST[...] above). Generally the php manual is a very good resource - often better than the primary sources: for example, it's often easier to understand MySQL stuff from the description of the PHP functions than from the MySQL manual.


This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.