user816829
user816829

Reputation: 13

If statement in PHP

$karthik=$_POST['myarray1'];
var_dump($karthik);


if($karthik=="ALTA 3.1-06 (CLTA 123.2-06) - Zoning Classification and Allowable Uses - Improved Land "){
    echo "correct";
}
else {
    echo "incorrect";
}

am getting array value as "ALTA 3.1-06 (CLTA 123.2-06) - Zoning Classification and Allowable Uses - Improved Land" but the result it is showing as incorrect i want to show it as a correct.

Upvotes: 0

Views: 98

Answers (5)

Nightwolf
Nightwolf

Reputation: 951

because $karthik is an array, $karthik will equal array, you need to specify with a key which value out of the array you would like. I believe the easiest would be to try:

if($karthik[0] == "ALTA 3.1-06 (CLTA 123.2-06) - Zoning Classification and Allowable Uses - Improved Land "){
    echo "correct";
}
else {
    echo "incorrect";
}

I am not sure if the space at the end is required or not.

Upvotes: 2

Mithun Sreedharan
Mithun Sreedharan

Reputation: 51274

try removing the extra space at the end of your hard coded string and use trim to remove any extra spaces i your POST variable

if(trim($karthik)=="ALTA 3.1-06 (CLTA 123.2-06) - Zoning Classification and Allowable Uses - Improved Land"){
    echo "correct";
}

Upvotes: 0

Sergii Nester
Sergii Nester

Reputation: 474

You have an extra space at the end of your "ALTA [...] Improved Land " string.

Upvotes: 0

Kevin Wang
Kevin Wang

Reputation: 3330

I noticed that you have a space attached to the end of

"ALTA 3.1-06 (CLTA 123.2-06) - Zoning Classification and Allowable Uses - Improved Land "

Maybe that's what is causing your error? You can always try trimming your strings.

Upvotes: 1

Stefan H Singer
Stefan H Singer

Reputation: 5504

You got an extra space at the end of your string in the if statement.

Upvotes: 2

Related Questions