SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whats wrong with this function?

    I keep getting parse errors

    PHP Code:
    function DoOnline($userid,$location)
       {

        
    $timenow time();
        
    $cutoff 300;
        
    $validtime time()-300;
        
    $userip $_SERVER['REMOTE_ADDR'];
        
    $formatedtime date("l jS F Y H:i");

         
    $query "DELETE FROM onlineusers WHERE lastactive < $validtime";
         
    $result mysql_query($query,$connection) or die(mysql_error());
    // 39
          
    if ($userid != "0"
           {
            
    $unique "SELECT memberid FROM onlineusers WHERE memberid=$userid";
            
    $checker = @mysql_query($unique,$connection) or die(mysql_error());
             
    $uniquetotals mysql_num_rows($checker);

              if (
    $uniquetotals == "0")
               {
                
    $insert "INSERT INTO onlineusers (id, ip, lastactive, lastacivenice, memberid, location, type, username) VLAUES ('', '$userip', $timenow, '$formatedtime', '$userid', '$location', 'USER', '$username')";
    $result mysql_query($insert,$connection) or die(mysql_error();
               }
              elseif (
    $uniquetotals != "0")
               { 
                
    $updateA "UPDATE onlineusers SET lastactive=$timenow WHERE memberid=$userid";
                
    $resultA mysql_query($updateA,$connection) or die(mysql_error();

                
    $updateB "UPDATE onlineusers SET lastactivenice=$formatedtime WHERE memberid=$userid";
                
    $resultB mysql_query($updateB,$connection) or die(mysql_error();
    // 60
                
    $updateC "UPDATE onlineusers SET location='$location' WHERE memberid=$userid";
                
    $resultC mysql_query($updateC,$connection) or die(mysql_error();
               }
             }

             if (
    $userid == "0"
              {
               
    $unique "SELECT ip FROM onlineusers WHERE ip='$userip'";
               
    $checker = @mysql_query($unique,$connection) or die(mysql_error());
                
    $uniquetotals mysql_num_rows($checker);

                 if (
    $uniquetotals == "0")
                  {
                   
    $insert "INSERT INTO onlineusers (id, ip, lastactive, lastacivenice, memberid, location, type, username) VLAUES ('', '$userip', $timenow, '$formatedtime', '$userid', '$location', 'guest', 'NOUSERNAME')";
                   
    $result mysql_query($insert,$connection) or die(mysql_error();
                  } 
                  if (
    $uniquetotals != "0")
                  { 
                
    $updateA "UPDATE onlineusers SET lastactive=$timenow WHERE ip='$userip'";
                
    $resultA mysql_query($updateA,$connection) or die(mysql_error();

                
    $updateB "UPDATE onlineusers SET lastactivenice=$formatedtime WHERE ip='$userip'";
                
    $resultB mysql_query($updateB,$connection) or die(mysql_error();

                
    $updateC "UPDATE onlineusers SET location='$location' WHERE ip='$userip'";
                
    $resultC mysql_query($updateC,$connection) or die(mysql_error();
               }
             }

           } 
    around the

    PHP Code:
    if ($uniquetotals == "0")
               {
                
    $insert "INSERT INTO onlineusers (id, ip, lastactive, lastacivenice, memberid, location, type, username) VLAUES ('', '$userip', $timenow, '$formatedtime', '$userid', '$location', 'USER', '$username')";
    $result mysql_query($insert,$connection) or die(mysql_error();
               } 
    bit. Any ideas?

  2. #2
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For starters VLAUES Should be VALUES

  3. #3
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lastacivenice should most likely be lastactivenice.

  4. #4
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, plus I would think that,
    $result = mysql_query(
    should just be
    mysql_query(

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I sorted out the typos but the parse error is still there

  6. #6
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Easy.

    You get the error in every line like this one, copy'n paste eh?
    PHP Code:
    $resultA mysql_query($updateA,$connection) or die(mysql_error()); 

  7. #7
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So why don't you post what the parse error is and post the code from the corresponding line number?

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
      function DoOnline($userid,$location)
       {

     
    $connection mysql_connect("localhost""$dbuser""$dbpass") or die(mysql_error());
     
    $db mysql_select_db($dbname$connection) or die(mysql_error());


        
    $timenow time();
        
    $validtime time()-300;
        
    $userip "$REMOTE_ADDR";
        
    $formatedtime date("l jS F Y H:i");

         
    $query "DELETE FROM onlineusers WHERE lastactive < $validtime";
         
    mysql_query($query,$connection) or die(mysql_error());

          if (
    $userid != "0"
           {
            
    $unique "SELECT memberid FROM onlineusers WHERE memberid=$userid";
            
    $checker = @mysql_query($unique,$connection) or die(mysql_error());
             
    $uniquetotals mysql_num_rows($checker);

              if (
    $uniquetotals == 0) {

    $insert "INSERT INTO onlineusers (id, ip, lastactive, lastactivenice, memberid, location, type, username) VALUES ('', '$userip', $timenow, '$formatedtime', '$userid', '$location', 'USER', '$username')";
    mysql_query($insert,$connection) or die(mysql_error());

        }
    else {

                
    $queryg "UPDATE onlineusers SET lastactive=$timenow WHERE memberid='$userid'";
                
    $result mysql_query($queryg,$connection) or die(mysql_error());

                
    queryr "UPDATE onlineusers SET lastactivenice='$formatedtime' WHERE memberid='$userid'";
                
    $result mysql_query($queryr,$connection) or die(mysql_error());

                
    $updatec "UPDATE onlineusers SET location='$location' WHERE memberid=$userid";
                
    mysql_query($updatec,$connection) or die(mysql_error();

               }

             }

             if (
    $userid == "0") {
               
    $unique "SELECT ip FROM onlineusers WHERE ip='$userip'";
               
    $checker = @mysql_query($unique,$connection) or die(mysql_error());
                
    $uniquetotals mysql_num_rows($checker);

                 if (
    $uniquetotals == "0") {

                   
    $insert "INSERT INTO onlineusers (id, ip, lastactive, lastactivenice, memberid, location, type, username) VALUES ('', '$userip', $timenow, '$formatedtime', '$userid', '$location', 'guest', 'NOUSERNAME')";
                   
    mysql_query($insert,$connection) or die(mysql_error();

                  } 

                  if (
    $uniquetotals != "0") { 

                
    $updateA "UPDATE onlineusers SET lastactive=$timenow WHERE ip='$userip'";
                
    mysql_query($updateA,$connection) or die(mysql_error();

                
    $updateB "UPDATE onlineusers SET lastactivenice=$formatedtime WHERE ip='$userip'";
                
    mysql_query($updateB,$connection) or die(mysql_error();

                
    $updateC "UPDATE onlineusers SET location='$location' WHERE ip='$userip'";
                
    mysql_query($updateC,$connection) or die(mysql_error();

               }

             }

           } 
    The error is reported to be on line 33

  9. #9
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the error say and which is line 33?

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error in /usr/local/psa/home/vhosts/domainusers/weingartner/httpdocs/online/functions.php on line 33

    The line changes depending on what I try to fix, but generally I think its around here:

    PHP Code:
    if ($uniquetotals == 0) { 

    $insert "INSERT INTO onlineusers (id, ip, lastactive, lastactivenice, memberid, location, type, username) VALUES ('', '$userip', $timenow, '$formatedtime', '$userid', '$location', 'USER', '$username')"
    mysql_query($insert,$connection) or die(mysql_error()); 

        } 
    else { 

                
    $queryg "UPDATE onlineusers SET lastactive=$timenow WHERE memberid='$userid'"
                
    $result mysql_query($queryg,$connection) or die(mysql_error()); 

                
    queryr "UPDATE onlineusers SET lastactivenice='$formatedtime' WHERE memberid='$userid'"
                
    $result mysql_query($queryr,$connection) or die(mysql_error()); 

                
    $updatec "UPDATE onlineusers SET location='$location' WHERE memberid=$userid"
                
    mysql_query($updatec,$connection) or die(mysql_error(); 

               } 

  11. #11
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I take it you do not have line numbers in your editer? One thing of note: You should not have 'quotations' around any numreric values in your queries.

  12. #12
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That should only be one query.
    PHP Code:
    mysql_query("UPDATE onlineusers SET lastactive = $timenow, lastactivenice = $formatedtime, location = '$location' WHERE memberid = $userid"$connection) or die(mysql_error(); 

  13. #13
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might be the problem.
    PHP Code:
    queryr 

  14. #14
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No way of testing the code but...
    PHP Code:
        function DoOnline($userid,$location) {
            
    $connection mysql_connect('localhost'$dbuser$dbpass) or die(mysql_error());
            
    $db mysql_select_db($dbname$connection) or die(mysql_error());
            
    $timenow time();
            
    $validtime time()-300;
            
    $userip $_SERVER['REMOTE_ADDR'];
            
    $formatedtime date('l jS F Y H:i');

            
    mysql_query("
                    DELETE FROM
                        onlineusers
                    WHERE
                        lastactive < 
    $validtime",
                    
    $connection) or die(mysql_error());

            if(
    $userid != "0") {
                
    $checker = @mysql_query("
                                    SELECT
                                        memberid
                                    FROM
                                        onlineusers
                                    WHERE
                                        memberid = 
    $userid",
                                    
    $connection) or die(mysql_error());
                
    $uniquetotals mysql_num_rows($checker);

                if(
    $uniquetotals == 0) {
                    
    mysql_query("
                            INSERT INTO
                                onlineusers
                                    (
                                    id,
                                    ip,
                                    lastactive,
                                    lastactivenice,
                                    memberid,
                                    location,
                                    type,
                                    username
                                    )
                            VALUES
                                    (
                                    '',
                                    
    $userip,
                                    
    $timenow,
                                    
    $formatedtime,
                                    
    $userid,
                                    '
    $location',
                                    'USER',
                                    '
    $username'
                                    )"
    ,
                            
    $connection) or die(mysql_error());
                } else {
                    
    mysql_query("
                            UPDATE
                                onlineusers
                            SET
                                lastactive = 
    $timenow,
                                lastactivenice = 
    $formatedtime,
                                location = '
    $location'
                            WHERE
                                memberid = 
    $userid",
                            
    $connection) or die(mysql_error();
                }
            }
            if(
    $userid == 0) {
                
    $checker = @mysql_query("
                                    SELECT
                                        ip
                                    FROM
                                        onlineusers
                                    WHERE
                                        ip = 
    $userip",
                                    
    $connection) or die(mysql_error());
                
    $uniquetotals mysql_num_rows($checker);
                if (
    $uniquetotals == 0) {
                    
    mysql_query("
                            INSERT INTO
                                onlineusers
                                    (
                                    id,
                                    ip,
                                    lastactive,
                                    lastactivenice,
                                    memberid,
                                    location,
                                    type,
                                    username
                                    )
                            VALUES
                                    (
                                    '',
                                    
    $userip,
                                    
    $timenow,
                                    
    $formatedtime,
                                    
    $userid,
                                    '
    $location',
                                    'guest',
                                    'NOUSERNAME')"
    ,
                            
    $connection) or die(mysql_error();
                }
                if (
    $uniquetotals != 0) { 
                    
    mysql_query("
                            UPDATE
                                onlineusers
                            SET
                                lastactive = 
    $timenow,
                                lastactivenice = 
    $formatedtime,
                                location = '
    $location'
                            WHERE
                                memberid = 
    $userid",
                            
    $connection) or die(mysql_error();
                }
            }
        } 

  15. #15
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Says theres a parse error on line 68

    I used:

    PHP Code:
    <?php


         
    function DoOnline($userid,$location) { 


            
    $connection mysql_connect('localhost'$dbuser$dbpass) or die(mysql_error()); 
            
    $db mysql_select_db($dbname$connection) or die(mysql_error()); 
            
    $timenow time(); 
            
    $validtime time()-300
            
    $userip $_SERVER['REMOTE_ADDR']; 
            
    $formatedtime date('l jS F Y H:i'); 

            
    mysql_query(
                    DELETE FROM 
                        onlineusers 
                    WHERE 
                        lastactive < 
    $validtime"
                    
    $connection) or die(mysql_error()); 

            if(
    $userid != "0" ) { 
                
    $checker = @mysql_query(
                                    SELECT 
                                        memberid 
                                    FROM 
                                        onlineusers 
                                    WHERE 
                                        memberid = 
    $userid"
                                    
    $connection) or die(mysql_error()); 
                
    $uniquetotals mysql_num_rows($checker); 

                if(
    $uniquetotals == 0) { 
                    
    mysql_query(
                            INSERT INTO 
                                onlineusers 
                                    ( 
                                    id, 
                                    ip, 
                                    lastactive, 
                                    lastactivenice, 
                                    memberid, 
                                    location, 
                                    type, 
                                    username 
                                    ) 
                            VALUES 
                                    ( 
                                    '', 
                                    
    $userip
                                    
    $timenow
                                    
    $formatedtime
                                    
    $userid
                                    '
    $location', 
                                    'USER', 
                                    '
    $username
                                    )"

                            
    $connection) or die(mysql_error()); 
                } else { 
                    
    mysql_query(
                            UPDATE 
                                onlineusers 
                            SET 
                                lastactive = 
    $timenow
                                lastactivenice = 
    $formatedtime
                                location = '
    $location
                            WHERE 
                                memberid = 
    $userid"
                            
    $connection) or die(mysql_error(); 
                } 
            } 
            if(
    $userid == 0) { 
                
    $checker = @mysql_query(
                                    SELECT 
                                        ip 
                                    FROM 
                                        onlineusers 
                                    WHERE 
                                        ip = 
    $userip"
                                    
    $connection) or die(mysql_error()); 
                
    $uniquetotals mysql_num_rows($checker); 
                if (
    $uniquetotals == 0) { 
                    
    mysql_query(
                            INSERT INTO 
                                onlineusers 
                                    ( 
                                    id, 
                                    ip, 
                                    lastactive, 
                                    lastactivenice, 
                                    memberid, 
                                    location, 
                                    type, 
                                    username 
                                    ) 
                            VALUES 
                                    ( 
                                    '', 
                                    
    $userip
                                    
    $timenow
                                    
    $formatedtime
                                    
    $userid
                                    '
    $location', 
                                    'guest', 
                                    'NOUSERNAME')"

                            
    $connection) or die(mysql_error(); 
                } 
                if (
    $uniquetotals != 0) { 
                    
    mysql_query(
                            UPDATE 
                                onlineusers 
                            SET 
                                lastactive = 
    $timenow
                                lastactivenice = 
    $formatedtime
                                location = '
    $location
                            WHERE 
                                memberid = 
    $userid"
                            
    $connection) or die(mysql_error(); 
                } 
            } 
        } 

    ?>
    On the other script, it says theres a parse error on this line:

    PHP Code:
    $queryr "UPDATE onlineusers SET lastactivenice='$formatedtime' WHERE memberid=$userid";
                
    mysql_query($queryr,$connection) or die(mysql_error()); 
    This is all going wrong! Any ideas whats happening?

  16. #16
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be I forgot to put semi quotes arround a value. It's really hard to tell without access to the database.
    PHP Code:
        function DoOnline($userid,$location) {
            
    $connection mysql_connect('localhost'$dbuser$dbpass) or die(mysql_error());
            
    $db mysql_select_db($dbname$connection) or die(mysql_error());
            
    $timenow time();
            
    $validtime time()-300;
            
    $userip $_SERVER['REMOTE_ADDR'];
            
    $formatedtime date('l jS F Y H:i');

            
    mysql_query("
                    DELETE FROM
                        onlineusers
                    WHERE
                        lastactive < '
    $validtime'",
                    
    $connection) or die(mysql_error());

            if(
    $userid != 0) {
                
    $checker = @mysql_query("
                                    SELECT
                                        memberid
                                    FROM
                                        onlineusers
                                    WHERE
                                        memberid = 
    $userid",
                                    
    $connection) or die(mysql_error());
                
    $uniquetotals mysql_num_rows($checker);

                if(
    $uniquetotals == 0) {
                    
    mysql_query("
                            INSERT INTO
                                onlineusers
                                    (
                                    id,
                                    ip,
                                    lastactive,
                                    lastactivenice,
                                    memberid,
                                    location,
                                    type,
                                    username
                                    )
                            VALUES
                                    (
                                    '',
                                    '
    $userip',
                                    '
    $timenow',
                                    '
    $formatedtime',
                                    
    $userid,
                                    '
    $location',
                                    'USER',
                                    '
    $username'
                                    )"
    ,
                            
    $connection) or die(mysql_error());
                } else {
                    
    mysql_query("
                            UPDATE
                                onlineusers
                            SET
                                lastactive = '
    $timenow',
                                lastactivenice = '
    $formatedtime',
                                location = '
    $location'
                            WHERE
                                memberid = 
    $userid",
                            
    $connection) or die(mysql_error();
                }
            }
            if(
    $userid == 0) {
                
    $checker = @mysql_query("
                                    SELECT
                                        ip
                                    FROM
                                        onlineusers
                                    WHERE
                                        ip = 
    $userip",
                                    
    $connection) or die(mysql_error());
                
    $uniquetotals mysql_num_rows($checker);
                if (
    $uniquetotals == 0) {
                    
    mysql_query("
                            INSERT INTO
                                onlineusers
                                    (
                                    id,
                                    ip,
                                    lastactive,
                                    lastactivenice,
                                    memberid,
                                    location,
                                    type,
                                    username
                                    )
                            VALUES
                                    (
                                    '',
                                    '
    $userip',
                                    '
    $timenow',
                                    '
    $formatedtime',
                                    
    $userid,
                                    '
    $location',
                                    'guest',
                                    'NOUSERNAME')"
    ,
                            
    $connection) or die(mysql_error();
                }
                if (
    $uniquetotals != 0) { 
                    
    mysql_query("
                            UPDATE
                                onlineusers
                            SET
                                lastactive = '
    $timenow',
                                lastactivenice = '
    $formatedtime',
                                location = '
    $location'
                            WHERE
                                memberid = 
    $userid",
                            
    $connection) or die(mysql_error();
                }
            }
        } 

  17. #17
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing though. Don't copy past code from the forums page. It can contain formating that will mess up your script. Always click on quote and copy the code from there.

  18. #18
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks for the tip


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
  •