Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Joseph Stout
Joseph Stout
4,740 Points

echo is not echoing..

Ive been trying to apply the "if/else" and "for loops" Ive learned from treehouse in some real world examples and I am just sandboxing a "Password Manager" type thing to kind of practice. However, everything is currently working, except the echo right after the if statement on line 6. What am I doing wrong?

       <?php
    $checkit = $_POST['numberadd'];
    if($checkit = 0){

       //Run this if we are deleting passwords.
       echo 'Are you sure you want to delete these items?';

    } else{

        //Run this if we are adding more passwords
        $num = $_POST['existnumber'];
        $addednums = $_POST['numberadd'] + $_POST['existnumber'];
        for($addednums; $addednums > $num; $addednums--){
        echo "<p>-------------------------</p><p>Site Name:<input type='text' name='site-name$addednums'></p>
        <p>Username:<input type='text' name='username$addednums'></p>
        <p>Password:<input type='text' name='pass$addednums'></p><p>-------------------------</p>";
        }
    }

        //Run this Always

        $numexist = $_POST['existnumber'];
        for($numexist; $numexist > 0; $numexist--){
        $sitenumexist = 'site-name' . "$numexist";
        $usernumexist = 'username' . "$numexist";
        $passnumexist = 'pass' . "$numexist";


        echo "<input type='text' name='$sitenumexist' value='$_POST[$sitenumexist]' style='display: none;'>
        <input type='text' name='$usernumexist' value='$_POST[$usernumexist]' style='display: none;'>
        <input type='text' name='$passnumexist' value='$_POST[$passnumexist]' style='display: none;'>";
        }

        ?>
Jeff Lemay
Jeff Lemay
14,268 Points

Re-posting code to see syntax highlighting

<?php
    $checkit = $_POST['numberadd'];
    if($checkit = 0){

       //Run this if we are deleting passwords.
       echo 'Are you sure you want to delete these items?';

    } else{

        //Run this if we are adding more passwords
        $num = $_POST['existnumber'];
        $addednums = $_POST['numberadd'] + $_POST['existnumber'];
        for($addednums; $addednums > $num; $addednums--){
        echo "<p>-------------------------</p><p>Site Name:<input type='text' name='site-name$addednums'></p>
        <p>Username:<input type='text' name='username$addednums'></p>
        <p>Password:<input type='text' name='pass$addednums'></p><p>-------------------------</p>";
        }
    }

        //Run this Always

        $numexist = $_POST['existnumber'];
        for($numexist; $numexist > 0; $numexist--){
        $sitenumexist = 'site-name' . "$numexist";
        $usernumexist = 'username' . "$numexist";
        $passnumexist = 'pass' . "$numexist";


        echo "<input type='text' name='$sitenumexist' value='$_POST[$sitenumexist]' style='display: none;'>
        <input type='text' name='$usernumexist' value='$_POST[$usernumexist]' style='display: none;'>
        <input type='text' name='$passnumexist' value='$_POST[$passnumexist]' style='display: none;'>";
        }

?>

1 Answer

Jeff Lemay
Jeff Lemay
14,268 Points

I think you want the if clause to be ($checkit == 0)

Joseph Stout
Joseph Stout
4,740 Points

yup, thank you, hard to think an equals sign has had me hung up for about an hour and a half now......