PHP Form question |
PHP Form question |
thomas |
Oct 9 2006, 10:08 AM
Post
#1
|
Group: Members Posts: 1 Joined: 9-October 06 Member No.: 375 |
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 |
Oct 9 2006, 12:46 PM
Post
#2
|
Jocular coder Group: Members Posts: 2,460 Joined: 31-August 06 Member No.: 43 |
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. |
Lo-Fi Version | Time is now: 18th April 2024 - 06:08 AM |