SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error in my code

    I have looked for the punctuation error (I have read the PHP Common Errors), but I cannot find the cause of the error.

    I have also removed anything unneeded, including any comments (I will add them back in after I get this running).

    The error is: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in change_password.php on line 49

    Line 49 is the $query.

    PHP Code:
    <?php
    if (!isset($_SESSION['first_name'])) {
        
    $url 'http://' $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
        if ((
    substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
            
    $url substr ($url0, -1); }
          
    $url .= '/index.php';
          
    header("Location: $url");
                } elseif (isset(
    $_POST['submitted'])) { 
                        
    $query "SELECT email, user_id FROM users_tbl WHERE first_name=($_SESSION['first_name'])";
    I am close to pulling my last hair.
    Each day is a learning experience.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The error is been caused by the following line because you have a random open and closing parenthesis that shouldn't be there.

    PHP Code:
    $query "SELECT email, user_id FROM users_tbl WHERE first_name=($_SESSION['first_name'])"
    The below code will fix the issue.

    PHP Code:
    $query "SELECT email, user_id FROM users_tbl WHERE first_name='" $_SESSION['first_name'] . "'"

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see what you did and it worked. I will have to study the code more when I get back to my computer tonight.

    Of course, fixing this gave me a new error (a simple one), and fixing that has given me several errors that I can work on tonight.
    Each day is a learning experience.

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    If it works perfectly the first time, you know you've done something wrong

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have managed to get my change_password to work, thanks to the help here.

    Now when I try a different login, I seem to be running into trouble. First, I logout and I suspect there is something wrong with my logout code. When I tried to change the password for a different user, it acted as if the session was still set (I think).
    PHP Code:
        <div id="main">
        <?php
        
    // If no first_name variable exists, redirect the user.
        
    if (!isset($_SESSION['first_name'])) {
            
    header("Location: http://www.recse.org/clergy/index.php");
            exit(); 
    // Quit the script.
        
    } else { // Logout the user.
        
    $_SESSION = array(); // Destroy the variables.
        
    session_destroy(); // Destroy the session itself.
        
    setcookie (session_name(), ''time()-300'/'''0); // Destroy the cookie.
        
    }
        echo 
    '<h3>You are now logged out. </h3><br />
        ?>
        </div>
    This code is giving me an error of:
    Warning: Cannot modify header information - headers already sent by (output started at /logout.php:24) in /homepages/4/d322583329/htdocs/dev/logout.php on line 37

    Line 37 is the setcookie line.
    Each day is a learning experience.

  6. #6
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The error is occurring because you currently have your PHP code wrapped inside a DIV element which is illegal as for a PHP header() function to work it needs to be before any white space and HTML code otherwise you will get the above error.

  7. #7
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like I need to rewrite my logout.php code. I will start with:
    PHP Code:
    <?php
    session_start
    ();
    if(!isset(
    $_SESSION['first_name'])) { // Not logged in
     
    include_once('index.php'); // send to index page
     
    die(); // stop processing
    }
    This is code I modified from another thread. StarLion at http://www.sitepoint.com/forums/show...snt-Other-Days had some code that does not use redirect, so I will give it a run and see what happens.
    Each day is a learning experience.


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
  •