Skip to content

EC for Week 7 if statement for $salutations

October 6, 2012

Hi everyone,

For those of you who did the extra credit and followed along in the lecture there are slight adjustments for the if statement.

This is the original:

$salutation = cleanup($_POST[‘salutation’]);
if(strlen ($salutation < 2)){
$salutation = ‘none’;
I believe instead it should be:
$salutation = cleanup($_POST[‘salutation’]);
if(strlen($salutation) < 2){
$salutation = ‘none’;
I found this out while I was testing that without the parenthesis around ($salutation) it does not recognize it as string length (strlen) and will output ‘none’ even if a user inputs Mr. However if a user inputs 3 or greater than it will output the numerical value correctly. My guess is it is picking up the if statement as a numerical value.
4 Comments leave one →
  1. October 6, 2012 1:51 pm

    Jason thank you so much. I have been trying to figure out the problem for a while now. I could not figure out what I was doing when it matched exactly to Derek’s page. Thank you for posting this to help those of us who need help.

    • October 6, 2012 1:55 pm

      I actually just tried but it still seems to say NONE.

      • October 6, 2012 2:10 pm

        Hi Danielle, I assume you’re kapland under PUBchttpd/htdocs… I looked at your form_student.php file and you didn’t update the if statement. Also the last modified date says 10/03/2012. If you make the changes I suggested it should work 😉

        FYI, I noticed you have the form_student.php~ in your php folder. I don’t believe that additional file is necessary.

  2. derek permalink*
    October 8, 2012 11:46 am

    The issue is that I conflated the string object (measuring the length of the string) with the comparison of that length to a standard simply by sloppy use of parentheses. It was a great catch by Jason.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: