Results 1 to 4 of 4

Thread: Parse error: syntax error unexpected 'echo'

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

    Default Parse error: syntax error unexpected 'echo'

    This error pops for the following line:

    PHP Code:
    <?php if(isset ($error)) (echo '<div id="login-errors">'.$error.'</div>'); ?>
    EDIT

    If I change "echo" to "print" it returnes no errors, but then it messes up the page layout and prints the following in the upper left corner:

    PHP Code:
    array (size=3)
        
    'username' => string 'dfdf' (length=4)
        
    'password' => string 'dfdfd' (length=5)
        
    'logintoadmincenter' => string 'Login' (length=5
    However, it does do somewhat, what it should be doing which is "print" 'Invalid Credentials' in the DIV.
    Last edited by Kage Kazumi; 10-21-2012 at 08:01 PM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
     <?php if(isset ($error)) {
          echo 
    '<div id="login-errors">'.$error.'</div>'
    ?>
    Use {} for if statements, rather than (). And don't end that with a ;. I'm not exactly sure what's not working there, but the code was written incorrectly, and it should now work.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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

    Default

    Quote Originally Posted by djr33 View Post
    PHP Code:
     <?php if(isset ($error)) {
          echo 
    '<div id="login-errors">'.$error.'</div>'
    ?>
    Use {} for if statements, rather than (). And don't end that with a ;. I'm not exactly sure what's not working there, but the code was written incorrectly, and it should now work.
    That creates a new error:

    Parse error: syntax error, unexpected '}', expecting ',' or ';'

    Here is what I have written incase I did it wrong:

    PHP Code:
    <?php if(isset ($error)) { echo '<div id="login errors">'.$error.'</div>' ?>
    Alright I added ";" at the end and it fixed it, but now the page is breaking layout and displaying:

    PHP Code:
    array (size=3
        
    'username' => string 'dfdf' (length=4
        
    'password' => string 'dfdfd' (length=5
        
    'logintoadmincenter' => string 'Login' (length=5
    So why is this PHP breaking my HTML layout and adding that code in the upper left corner which is not what it is suppose to do:

    My PHP

    PHP Code:
    <?php
        session_start
    ();
        if(
    $_POST && isset($_POST['logintoadmincenter'])) 
        {
            include_once 
    '/include/connection.php';
            
            
    $username $_POST['username'];
            
    $password $_POST['password'];
            
            if (empty(
    $username) && empty($password)) 
            {
                
                
    $error "Please fill in the required fields";
            }
            else 
            {
                print 
    "<pre>";
                
    var_dump($_POST);
                
    $username strip_tags ($username);
                
    $password strip_tags ($password);
                
                
    $username mysql_real_escape_string ($username);
                
    $password mysql_real_escape_string ($password);
                
    $password md5($password);
                
    $sql mysql_query("SELECT * From Members WHERE name = '$username' && password = '$password' LIMIT 1") or die (mysql_error ());
                
    $num_rows mysql_num_rows ($sql);
                if (
    $num_rows == 1)
                {
                    
    $rows mysql_fetch_array($sql);
                    
    extract ($rows);
                    
                    
    $_SESSION['username'] = $name;
                    
    $_SESSION['level'] = $access_level;
                    
                    if (isset ($
    $_SESSION['username']));
                    {
                        
    $update msql_query("UPDATE Members SET last_log_time = now()") or die(mysql_error());
                        
                        
    header("location: index.php");
                    }
                }
                else
                {
                    
    $error 'Invalid Credentials';
                }
            }
        }
    ?>
    Never mind I found the issue:

    PHP Code:
    print "<pre>";
                
    var_dump($_POST); 
    Last edited by Kage Kazumi; 10-21-2012 at 08:00 PM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Alright I added ";" at the end and it fixed it,
    Oops, I missed that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Similar Threads

  1. Parse error: syntax error
    By dcr33 in forum PHP
    Replies: 3
    Last Post: 01-01-2012, 12:05 PM
  2. Replies: 1
    Last Post: 01-28-2011, 02:39 AM
  3. Parse error: syntax error, unexpected $end
    By heavensgate15 in forum PHP
    Replies: 2
    Last Post: 02-24-2010, 05:38 AM
  4. Replies: 2
    Last Post: 02-12-2010, 08:53 AM
  5. Replies: 1
    Last Post: 04-26-2008, 11:22 AM

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
  •