Moloney Posted March 23, 2013 Report Posted March 23, 2013 (edited) 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 March 23, 2013 by Stephenius Quote
falkencreative Posted March 23, 2013 Report Posted March 23, 2013 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? 1 Quote
Moloney Posted March 23, 2013 Author Report Posted March 23, 2013 Thanks, I think this should help. I'm going to have a go at it again and post back. I'm guessing that something along the lines of OR || inside the elseif statement should be the way to go. Quote
Moloney Posted March 23, 2013 Author Report Posted March 23, 2013 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 Quote
falkencreative Posted March 24, 2013 Report Posted March 24, 2013 DOES THIS SAME LOGIC WITH IF ELSESTATEMENTS APPLY IN OTHER PROGRAMMING LANGUAGES LIKE JAVASCRIPT? Yes. Quote
Recommended Posts
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.