Jump to content
Killersites Forums

Problem With An If Statement


Moloney
 Share

Recommended Posts

Hi all,

There is something simple i am probably missing here, can anyone see it?

I've tried debugging it for a while now.

 

This is the html part:

 

<p> Company Name: <input type="text" name="company_name" value="Company Name" /> </p>

 

 

This is the php part

 

$name = $_REQUEST['company_name'];

 

if (!EMPTY($name)) {

$condition2 = TRUE;

}

elseif (!EMPTY($name) == FALSE) {

echo "<p> Sorry, the form has not been submitted. A Company name has

not been submitted</p>";

}

elseif ( $name == "Company Name") {

echo "<p> Sorry, the form has not been submitted. A <b>valid</b> Company name has not been submitted</p>";

}

 

The first 2 parts of the statement work but the third part of the statement does not.

I can't figure out why the third part is not echoed.

It looks like $name is the same as "Company Name".

 

Any ideas what is wrong?

 

Thanks

Edited by Stephenius
Link to comment
Share on other sites

The problem isn't that it isn't working. The problem is that you have a logic error in your code -- specifically, if $name isn't empty (if it contains something the user entered, or "Company Name"), the if statement will always set $condition2 to true, and PHP will never continue down to check out the last elseif. PHP will only check the elseif's if the previous if or elseif is false. Hopefully that helps get you started?

  • Upvote 1
Link to comment
Share on other sites

i FIGURED MORE THAN ONE WAY TO MAKE IT WORK. AND I UNDERSTAND NOW WHAT YOU MEAN BY LOGIC. DOES THIS SAME LOGIC WITH IF ELSE

STATEMENTS APPLY IN OTHER PROGRAMMING LANGUAGES LIKE JAVASCRIPT?

 

FIRST ONE WAS TO SIMPLY REARRANGE THE ORDER OF THE IF, & IFELSE;

 

if ($name == "Company Name"){

echo "<p> Sorry, the form has not been submitted. A <b>valid</b> Company name has not been submitted</p>";

}

 

elseif (!EMPTY($name)) {

$condition2 = TRUE;

}

 

elseif (!EMPTY($name) == FALSE) {

echo "<p> Sorry, the form has not been submitted. A Company name has

not been submitted</p>";

}

 

SECOND ONE WAS TO ADD ANOTHER IF STATEMENT;

 

if (!EMPTY($name)) {

$condition2 = TRUE;

}

 

elseif (!EMPTY($name) == FALSE) {

echo "<p> Sorry, the form has not been submitted. A Company name has

not been submitted</p>";

}

 

if ($condition2==TRUE && $name=="Company Name") {

echo "<p> Sorry, the form has not been submitted. A <b>valid</b> Company name has not been submitted</p>";

}

 

 

THANKS AGAIN

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...