Results 1 to 8 of 8

Thread: echo not working

  1. #1
    Join Date
    Oct 2012
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default echo not working

    I'm creating the login page for my admin area to my CMS I am working on. I am using the "if" statement to echo instructions if the form input fields are blank. However, the echo will not work inside the "if" statement. I tried moving the echo outside of the "if" statement and it works fine and echos like it should except when inside the if statement.

    admin-login.php

    PHP
    PHP Code:
    <?php include_once ('include/scripts/login.php'); ?>
    HTML
    HTML Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <link rel="stylesheet" type="text/css" href="style/css/style.css"></link>
    <script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
    </head>
    
    <body>
    <!--START: Log In Wrapper-->
    <div id="login-wrapper">
    	<!--START: Error Display-->
        	<div id="login-errors">
            	&nbsp;
            </div>
    	<!--END: Error Display-->
    	<!--START: Log In Form-->
        <div id="login-form">
        	<h2>Admin Login Panel</h2><!--Login Header-->
            <!--START: Login Form-->
            <form method="post" action="admin-login.php">
            	<!-- START: Form Element USERNAME-->
            	<div class="form-element">
                	<label for="Username" class="admin-login-label">Username</label><!--Username Label-->
                    <input type="text" name="username" placeholder="Enter Username" id="admin-username"/><!--Username Input-->
                </div>
                <!-- END: Form Element USERNAME-->
                <!-- START: Form Element PASSWORD-->
            	<div class="form-element">
                	<label for="Password" class="admin-login-label">Password</label><!--Password Label-->
                    <input type="text" name="password" placeholder="Enter Passowrd" id="admin-password"/><!--Password Input-->
                </div>
                <!-- END: Form Element PASSWORD-->
                <!-- START: Form Element SUBMIT-->
            	<div class="form-element">
                	<label></label><!--Leave Blank-->
                    <input type="Submit" name="logintoadmincenter" value="Login" id="admin-login-button" /><!--Username Input-->
                </div>
                <!-- END: Form Element SUBMIT-->
            </form>
            <!--END: Login Form-->
        </div>
        <!--END: Log In Form-->
    </div>
    <!--END: Log In Wrapper-->
    </body>
    </html>
    login.php

    PHP Code:
    <?php

        
    if(isset($_post['logintoadmincenter'])) {
                
            include_once 
    '.:include/connection.php';
            
    $username $_post['username'];
            
    $password $_post['password'];
            if (empty(
    $username) || empty($password)) {
                
                echo (
    "Please fill in the required fields");
                
            }
        
        }
    ?>
    I receive no errors. It just doesn't echo, even if written as:

    PHP Code:
    echo ('Please fill in the required fields'); 
    OR

    PHP Code:
    echo "Please fill in the required fields"
    OR

    PHP Code:
    echo 'Please fill in the required fields'
    Last edited by Kage Kazumi; 10-21-2012 at 07:19 PM.

  2. #2
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,521
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    That means that the statement is never returning true.

    Just before the if statement, echo out the values of $username, $password and their respective lengths.

  3. #3
    Join Date
    Oct 2012
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by keyboard1333 View Post
    That means that the statement is never returning true.

    Just before the if statement, echo out the values of $username, $password and their respective lengths.
    Being a beginner you have only confused me more. What do you mean by "echo out the values?"

  4. #4
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,521
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Put in this before the if statement
    Code:
    echo $username . '<br />';
    echo $password . '<br />';
    echo strlen($username) . '<br />';
    echo strlen($password) . '<br />';
    And tell me what the four values are...

  5. #5
    Join Date
    Oct 2012
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I just get a couple of errors that say:

    Undefined variable: username

    Undefined variable: password


    If it is above both if statements.

    However, above the second if statement it does nothing and echos nothing.

    EDIT

    When I put the variables and the echos above both "if" statements I get two errors:

    Undefined index: password
    Undefined index: username

    However, it does echo two zeros below the errors.
    Last edited by Kage Kazumi; 10-21-2012 at 05:40 PM. Reason: add info

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by Kage Kazumi View Post
    When I put the variables and the echos above both "if" statements I get two errors:

    Undefined index: password
    Undefined index: username
    that would imply that your form is not submitting those fields...

    try changing this
    PHP Code:
    if (empty($username) || empty($password)) { 
                 
                echo (
    "Please fill in the required fields"); 
                 
            } 
    to this
    PHP Code:
    if (empty($username) || empty($password)) { 
                 
                echo 
    "Please fill in the required fields"
                 
            }else{
                print 
    "<pre>";
                
    var_dump$_POST );
            } 

  7. #7
    Join Date
    Oct 2012
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I thanks for the help. However, I went ahead and started working on it adding more information. So the 'echo' is not there. I will post again if I receive any new errors regarding the echo later in the script.

    EDIT

    Oh man I am an idiot. I set the error to display only if the button was pressed. So yes it does work. :facepalm:
    Last edited by Kage Kazumi; 10-21-2012 at 08:03 PM.

  8. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by Kage Kazumi View Post
    PHP Code:
        if(isset($_post['logintoadmincenter'])) {
            include_once 
    '.:include/connection.php';
            
    $username $_post['username'];
            
    $password $_post['password'];
            if (empty(
    $username) || empty($password)) {
                echo (
    "Please fill in the required fields");
            }
        } 
    Also (and I'm sorry for not mentioning this earlier; I completely overlooked it):
    $_POST (the automatically created superglobal that holds HTTP POST data) is not the same as $_post (which will only exist if you create it, and holds only what you assign to it).

Similar Threads

  1. echo nothing?
    By begeiste in forum PHP
    Replies: 3
    Last Post: 11-22-2011, 07:02 PM
  2. echo css
    By ggalan in forum PHP
    Replies: 7
    Last Post: 06-29-2010, 01:13 AM
  3. echo inside an echo?
    By crobinson42 in forum PHP
    Replies: 5
    Last Post: 05-20-2010, 02:32 AM
  4. jasoncalendar echo
    By Hubertus in forum JavaScript
    Replies: 1
    Last Post: 07-11-2009, 03:47 PM
  5. echo...
    By pavmoxo in forum PHP
    Replies: 11
    Last Post: 04-28-2006, 04:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •