Page 1 of 1

really easy question but baffling me

Posted: Mon Mar 15, 2004 10:41 am
by nutstretch
I have a set of radio buttons in a group
one returns yes
one returns no
i can read then in to my next for that is no problem but for some reason i am having problems checking to see which one was returned..

$brochure = $_POST['brochure'];

reads in the value

I have tried using an if statement to see if it is yes but noting seems to work
i have tried
$ bro = "yes";
if ($brochure == $bro)
{ etc
and
if ($brochure == 'yes')
{ etc

what is the correct syntax for comparing strings to see is they are the same I acn find syntax for loads of others but this must be too simple for the book!!!!

please help if i bang my head anymore i will have to replaster again....

Posted: Mon Mar 15, 2004 10:48 am
by m3mn0n

Code: Select all

<?php
echo '<pre>';
     print_r($_POST);
echo '</pre>';
?>
That should display all the elements, and help you pick which to use.

Posted: Mon Mar 15, 2004 10:48 am
by Bill H
You are looking for strcmp() function.

But for radio buttons I usually use a value of 0 (for no) and 1 ( for yes).

Posted: Mon Mar 15, 2004 10:54 am
by nutstretch
Thanks using numbers works ok

but how do you compare 2 strings to see if they are the same? I may need that one day lol

Posted: Mon Mar 15, 2004 10:57 am
by Bill H
The first sentence in my post: strcmp();

Code: Select all

$int =  strcmp($string1,$string2);  // check the manual

Posted: Mon Mar 15, 2004 10:59 am
by nutstretch
i tried that and it didn't want to know I'll check my syntax again thanks.

Posted: Mon Mar 15, 2004 7:15 pm
by Goowe

Code: Select all

<?php
$value['one'] == 'chicken';
$value['two'] == 'chicken';
$value['three'] == 'turkey';

if($value['one'] == $value['two'])
{
   echo "The values are equal to eachother";
}
   else
{
   echo "The values are not equal.":
}

if($value['one'] == $value['three'])
{
   echo "The values are not equal to eachother";
}
   else
{
   echo "The values are equal to eachother";
}
?>
Is this what you meant? Hope it helps, sorry if I didn't answer your question.

Posted: Mon Mar 15, 2004 7:23 pm
by Unipus
You must have some other problem (probably with variable names/values) because == is the correct operator for string comparisons.