The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> PHP Form question
thomas
post 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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 9 2006, 12:46 PM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



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.


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th April 2024 - 06:08 AM