How to use IF in PHP, simple

In this posting we will look shortly on using IF in PHP scripts.
In the code below you can see three radiobuttons and a submitbutton. When you tick one of the radiobuttons and click the submit you will put a string into the variable $check that will be shown on submit.

We read the value using $_POST['question'], and with IF we assign a string to the variable, depending on wich radiobutton was the selected one.

In the radiobuttons on the HTML form field you can see that the values are set to 'yes', 'no' and 'unsure', this is what we look for. If you have other input types in your form, then what you look for are these VALUES.

Here is the code.


if (isset($_POST['readme']))  { 

function checkme() {
$question = $_POST['question'];
if ( $question == 'yes' ) { $check = "You like PHP!"; }
if ( $question == 'no' ) { $check = "You don't like PHP?"; }
if ( $question == 'unsure' ) { $check = "You are unsure.."; }
echo $check;

echo "<HTML>

<TD>Do you like PHP: </TD> 
<TD><INPUT TYPE='radio' NAME='question' VALUE='yes'> Yes</TD> 

<TD><INPUT TYPE='radio' NAME='question' VALUE='no'> No</TD> 

<TD><INPUT TYPE='radio' NAME='question' VALUE='unsure'> Unsure</TD> 

<TD><INPUT TYPE='submit' NAME='readme' VALUE='Okay, try this'> 


In the next post I will show you how IF/ELSE works in PHP.