zero-perfoliate
zero-perfoliate

Author Topic: String in if else statement doesn't work.  (Read 268 times)

Offline jake edwards

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
String in if else statement doesn't work.
« on: November 12, 2009, 06:40:33 PM »
I have specified a variable in a href, but the variable won't work in an ifelse statement.  What am I doing wrong?
In the following example I always get 'other' when I should be getting 'hello'.

Example:
Quote
<a href='/site.php?section=helloworld'>Link[/url] //link to site.php

//in site.php
$section = $_GET['section'];
  if  ($section == "helloworld")
{
echo "hello";
  }
elseif ($section == "goodbye")
{
echo "goodbye";
  }
else
{
echo "other";
  }

Offline kris540

  • PHP Workers
  • **
  • Posts: 23
  • Karma: +0/-0
    • Share Expense
Re: String in if else statement doesn't work.
« Reply #1 on: November 13, 2009, 04:41:04 AM »
try it this way:
Code: [Select]
<a href='/site.php?section=helloworld'>Link[/url] //link to site.php

//in site.php
$section = $_GET['section'];
if($section != ""){
if($section == "helloworld"){
echo "hello";
    }
    if($section == "goodbye"){
    echo "goodbye";
}
}else{
echo "other";
}

 

zero-perfoliate