really easy question but baffling me

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

really easy question but baffling me

Post 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....
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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).
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

The first sentence in my post: strcmp();

Code: Select all

$int =  strcmp($string1,$string2);  // check the manual
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

i tried that and it didn't want to know I'll check my syntax again thanks.
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post 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.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

You must have some other problem (probably with variable names/values) because == is the correct operator for string comparisons.
Post Reply