Recent error message

68 views
Skip to first unread message

Jeremy

unread,
May 2, 2014, 11:37:53 AM5/2/14
to ajax...@googlegroups.com
My apologies for the lack of version number, not sure how to obtain it as I had installed the chat some time ago.  However, only recently (I think after my server was updated to PHP 5.4) did I start to receive an error message regarding the Public Static functions.  I updated all functions within lib/class/AJAXChatEncoding.php file to be "public static function" instead of just function.  I also updated lib/class/AJAXChatFileSystem.php with "public static function".

However, I now receive an error: <b>Warning</b>: mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2) in <b>/homepages/19/d252313221/htdocs/nordicrage/chat/lib/data/users.php</b> on line <b>22</b><br />

When I change error_reporting(E_ALL); to error_reporting(0);, I am provided with an updated error message: Couldnt execute query (22) - SELECT login, password, rank, tag, member_id FROM cws_members

Since this is custom code changes, I doubt you will be able to assist me too much.  However, it was code that had been working fine until recently.  ANY help would be great!

Host: 1&1
Website: http://nordicrage.webbled.com - unfortunately, you will have to register in order to use the chatroom if you wanted to view it.

Please let me know if there's any chance you could help.

Some code from lib/data/users.php:
/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) Sebastian Tschan
 * @license GNU Affero General Public License
 * @link
https://blueimp.net/ajax/
 */


// List containing the registered chat users:
$users
= array();

// Default guest user (don't delete this one):
$users
[0] = array();
$users
[0]['userRole'] = AJAX_CHAT_GUEST;
$users
[0]['userName'] = null;
$users
[0]['password'] = null;
$users
[0]['channels'] = array(0);

// PCW user registration
$sql
= "SELECT login, password, rank, tag, member_id FROM cws_members";
$sqlresult
= mysql_query($sql) or die ("Couldnt execute query (22) - " . $sql . " :: " . mysql_error());
while ($row = mysql_fetch_array($sqlresult)) {
 $login
= trim($row["login"]);
 $password
= $row["password"];
 $rank
= $row["rank"];
 $tag
= trim($row["tag"]);
 $member_id
= $row["member_id"];
 $sql2
= "SELECT rank_value FROM cws_ranks WHERE rank_id = ".$rank;
 $sqlresult2
= mysql_query($sql2) or die ("Couldnt execute query 2");
 $rank_value
= mysql_result($sqlresult2, 0, "rank_value");
 $users
[$member_id] = array();
 $users
[$member_id]['userName'] = $login;
 $users
[$member_id]['password'] = $password;
 $users
[$member_id]['tag'] = $tag;
 
if ($rank_value == '10'){        // Admins/leaders
  $users
[$member_id]['userRole'] = AJAX_CHAT_ADMIN;
  $users
[$member_id]['channels'] = array(0,1,2,3,4,5,6,7,8,9);
 
}elseif ($rank_value < '10' && $rank_value >= '8'){  // HS (9); General (8); Diplomat (8)
  $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
  $users
[$member_id]['channels'] = array(0,1,2,3,4,5,6,7,8,9);
 
}elseif ($rank_value < '10' && $rank_value >= '7'){  // Council (7);
  $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
  $users
[$member_id]['channels'] = array(0,2,3,4,5,6,7,8,9);
 
}elseif ($rank_value < '8' && $rank_value >= '4'){  // Alliance members
  $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
  $users
[$member_id]['channels'] = array(0,2,3,4,5,6,7,8);
 
}elseif ($rank_value == '3'){       // Allies
  $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
  $users
[$member_id]['channels'] = array(0,5,6,7,8);
 
}else{ // Everyone else
 
//$users[$member_id]['userRole'] = AJAX_CHAT_USER;
 
//$users[$member_id]['channels'] = array(0);
 
}
 
switch ($member_id){
 
case 1: // Morph
 
case 2: // Check
   
//array_push($users[$member_id]['channels'],4); // E_C
   
break;
 
}
}

/*
// Sample admin user:
$users[1] = array();
$users[1]['userRole'] = AJAX_CHAT_ADMIN;
$users[1]['userName'] = 'admin';
$users[1]['password'] = 'admin';
$users[1]['channels'] = array(0,1,2,3);
// Sample moderator user:
$users[2] = array();
$users[2]['userRole'] = AJAX_CHAT_MODERATOR;
$users[2]['userName'] = 'moderator';
$users[2]['password'] = 'moderator';
$users[2]['channels'] = array(0,1);
// Sample registered user:
$users[3] = array();
$users[3]['userRole'] = AJAX_CHAT_USER;
$users[3]['userName'] = 'user';
$users[3]['password'] = 'user';
$users[3]['channels'] = array(0,1,2);
*/




Frug

unread,
May 2, 2014, 12:30:40 PM5/2/14
to ajax...@googlegroups.com
Does it say anything -after- the part of the error message you list here?

 Couldnt execute query (22) - SELECT login, password, rank, tag, member_id FROM cws_members

Is that -all- it says?

I see from your code that message is followed by :: and then the cause of the error. That's the part that will tell you why.

You should consider switching from mysql_ to mysqli_ functions. See: https://wikis.oracle.com/display/mysql/Converting+to+MySQLi

 
case 2<span
...

Jeremy

unread,
May 2, 2014, 4:08:05 PM5/2/14
to ajax...@googlegroups.com
Sorry, I replied to the email, not this message board, so here is what I had emailed.
Yes, it shows the same error message from the "warning" mentioned earlier, so I had left it off to try to keep things clean.  Here is the full error:

XML Parsing Error: syntax error
Location: http://nordicrage.webbled.com/chat/
Line Number 1, Column 1:

Couldnt execute query (22) - SELECT login, password, rank, tag, member_id FROM cws_members :: Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2)
And thanks for the input, I will have to look into this MySQLi change-over.  My site uses a CMS called PCW, that no longer exists except through me (I was a bigtime mod-der for it).  I taught myself PHP and my sites have been functioning for a few years without much updating, lol.  I see with PHP 5, I might want to revisit the code :)
Also, after some more trial and error, I figured there was an issue pulling the DB connection used by the rest of the site.  So I pulled in my connection strings into the users.php file and that seemed to get it to work, but with all those public static error messages.  Perhaps my version of the chatroom is too outdated.  I just found the version.txt file, 0.8.3 standalone.  Maybe I will try to do an update, but I made a bunch of changes I'll have to make sure not to lose :)

Frug

unread,
May 2, 2014, 7:01:17 PM5/2/14
to ajax...@googlegroups.com
If anything gets me to move off google groups it's that annoying email stuff because I can never figure out why it sends me posts in emails when it does.

I'm thinking the problem is because this code you've provided is using mysql_connect but it does not actually establish a connection first. That may have worked in the past, but it's a very old way of doing things. It's also kinda hard to read code because who knows where the actual connection was established?

In the past, using old mysql_ procedural style would have created a connection and left it open unless someone closed it. So earlier on in the code somewhere I assume the connection was just left open and this worked. I'm guessing that's not happening any more, maybe the new server detects that mysqli is available and chat or your forum script switched to it, and the connection is no longer left open.

Jeremy

unread,
May 2, 2014, 9:47:59 PM5/2/14
to ajax...@googlegroups.com
haha, yea, but it's also integrated into Google, which is a nice plus, since Google runs my life at least.  I didn't even know they had such a place :)

Anyways, that's what I was figuring was that my code was using my previously established connection, so I tried a new connection within this code.  I was hoping the ajax script did connect prior to the user.php file, but I guess not.  And yes, my site is very old and using old PHP code :)  Will take a lot to update, I think, lol.  Thanks for your help thus far, though.  I'm trying to add a new connection string in the user.php file and that seems to settle that error.  However, I am not able to properly get my added code to work properly for obtaining the user lists from my PCW CMS (which is why I have this code).  I doubt you will be able to help me much more, unless you want to try and I can provide you with more code.

Jeremy

unread,
May 5, 2014, 2:54:06 PM5/5/14
to
Okay, sorry to bother you again, but I am having trouble finishing up updating the users.php customization.  The include file contains the connection details.  Also, I added a test username and password.  I am able to log in with the test information user/user.  There are some 'warnings' and other errors that can be hidden with the suppress error reporting - 3 strict messages about the date() function and timezones and 3 messages about editing header info.  Anyways, ignoring those, I appear to have trouble now creating my own user list based on my own tables.  At least, I receive an error message of "Invalid username.", when my list should match that of the users who can access the website (I am trying to get the same username/password combo as that of the website itself).  I thought maybe it was the encryption of the password, but the error is stating the username is invalid.  As mentioned earlier, it appeared to work fine before.  However, I updated all the files and updating the users.php file to look like below:

// List containing the registered chat users:
$users
= array();

// Default guest user (don't delete this one):
$users
[0] = array();
$users
[0]['userRole'] = AJAX_CHAT_GUEST;
$users
[0]['userName'] = null;
$users
[0]['password'] = null;
$users
[0]['channels'] = array(0);

// PCW user registration

include
"../phpclanwebsite/config.php";
$connection
= mysqli_connect("$mysql_host","$mysql_login","$mysql_pass","$mysql_database") or die("Error " . mysqli_error($connection));
$sql
= "SELECT login, password, rank, tag, member_id FROM cws_members" or die("Error on line 30.." . mysqli_error($connection));
$sqlresult
= $connection->query($sql);
while ($row = mysqli_fetch_array($sqlresult)) {

    $login
= trim($row["login"]);
    $password
= $row["password"];
    $rank
= $row["rank"];
    $tag
= trim($row["tag"]);
    $member_id
= $row["member_id"];


    $sql2
= "SELECT rank_value FROM cws_ranks WHERE rank_id = ".$rank or die ("Couldnt execute line 43");
    $sqlresult2
= $connection->query($sql2);
   
//$rank_value = mysql_result($sqlresult2, 0, "rank_value");
    $rowv
= mysqli_fetch_array($sqlresult2);  //Not sure about this row yet
    $rank_value
= $rowv["rank_value"];
  //Not sure about this row yet

    $users
[$member_id] = array();

    $users
[$member_id]['userName'] = $login;
    $users
[$member_id]['password'] = $password;
    $users
[$member_id]['tag'] = $tag;

   
if ($rank_value == '10'){                                // Admins/leaders
        $users
[$member_id]['userRole'] = AJAX_CHAT_ADMIN;
        $users
[$member_id]['channels'] = array(0,1,2,3,4,5,6,7,8,9);

   
}elseif ($rank_value < '10' && $rank_value >= '8'){        // HS (9); General (8); Diplomat (8)
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,1,2,3,4,5,6,7,8,9);

   
}elseif ($rank_value < '10' && $rank_value >= '7'){        // Council (7);
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,2,3,4,5,6,7,8,9);

   
}elseif ($rank_value < '8' && $rank_value >= '4'){        // Alliance members
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,2,3,4,5,6,7,8);

   
}elseif ($rank_value == '3'){                            // Allies
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,5,6,7,8);

   
}else{ // Everyone else
       
//$users[$member_id]['userRole'] = AJAX_CHAT_USER;
       
//$users[$member_id]['channels'] = array(0);
   
}
}

// Sample user:
$users
[9999999] = array();
$users
[9999999]['userRole'] = AJAX_CHAT_USER;
$users
[9999999]['userName'] = 'user';
$users
[9999999]['password'] = 'user';
$users
[9999999]['channels'] = array(0,5);


Any possible houghts on the matter?  Or am I on my own to figure out since it's an antiquated CMS?  :)

Thanks again for any assistance you may be able to provide.

Jeremy

unread,
May 5, 2014, 3:12:16 PM5/5/14
to ajax...@googlegroups.com
Ignore previous msg :)

I compared my old CustomAjaxChat.php file and noticed I had made changes in there as well to obtain the username and passwords.  My apologies.  The only thing left are the other strict msgs and the 2 lines I highlighted in red below, which pertains more to new PHP coding that I am trying to learn on my own. 



On Monday, May 5, 2014 2:52:49 PM UTC-4, Jeremy wrote:
Okay, sorry to bother you again, but I am having trouble finishing up updating the users.php customization.  The include file contains the connection details.  Also, I added a test username and password.  I am able to log in with the test information user/user.  There are some 'warnings' and other errors that can be hidden with the suppress error reporting - 3 strict messages about the date() function and timezones and 3 messages about editing header info.  Anyways, ignoring those, I appear to have trouble now creating my own user list based on my own tables.  At least, I receive an error message of "Invalid username.", when my list should match that of the users who can access the website (I am trying to get the same username/password combo as that of the website itself).  I thought maybe it was the encryption of the password, but the error is stating the username is invalid.  As mentioned earlier, it appeared to work fine before.  However, I updated all the files and updating the users.php file to look like below:

// List containing the registered chat users:
$users
= array();

// Default guest user (don't delete this one):
$users
[0] = array();
$users
[0]['userRole'] = AJAX_CHAT_GUEST;
$users
[0]['userName'] = null;
$users
[0]['password'] = null;
$users
[0]['channels'] = array(0);

// PCW user registration

include
"../phpclanwebsite/config.php";
$connection
= mysqli_connect("$mysql_host","$mysql_login","$mysql_pass","$mysql_database") or die("Error " . mysqli_error($connection));
$sql
= "SELECT login, password, rank, tag, member_id FROM cws_members" or die("Error on line 30.." . mysqli_error($connection));
$sqlresult
= $connection->query($sql);
while ($row = mysqli_fetch_array($sqlresult)) {

    $login
= trim($row["login"]);
    $password
= $row["password"];
    $rank
= $row["rank"];
    $tag
= trim($row["tag"]);
    $member_id
= $row["member_id"];


    $sql2
= "SELECT rank_value FROM cws_ranks WHERE rank_id = ".$rank or die ("Couldnt execute line 43");

    $sqlresult2
= $connection->query($sql2);
   
//$rank_value = mysql_result($sqlresult2, 0, "rank_value");
    $rowv
= mysqli_fetch_array($sqlresult2);  //Not sure about this row yet
    $rank_value
= $rowv["rank_value"];
  //Not sure about this row yet

    $users
[$member_id] = array();

    $users
[$member_id]['userName'] = $login;
    $users
[$member_id]['password'] = $password;
    $users
[$member_id]['tag'] = $tag;

   
if ($rank_value == '10'){                                // Admins/leaders
        $users
[$member_id]['userRole'] = AJAX_CHAT_ADMIN;
        $users
[$member_id]['channels'] = array(0,1,2,3,4,5,6,7,8,9);

   
}elseif ($rank_value < '10' && $rank_value >= '8'){        // HS (9); General (8); Diplomat (8)
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,1,2,3,4,5,6,7,8,9);

   
}elseif ($rank_value < '10' && $rank_value >= '7'){        // Council (7);
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,2,3,4,5,6,7,8,9);

   
}elseif ($rank_value < '8' && $rank_value >= '4'){        // Alliance members
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,2,3,4,5,6,7,8);

   
}elseif ($rank_value == '3'){                            // Allies
        $users
[$member_id]['userRole'] = AJAX_CHAT_USER;
        $users
[$member_id]['channels'] = array(0,5,6,7,8);

   
}else{ // Everyone else
       
//$users[$member_id]['userRole'] = AJAX_CHAT_USER;
       
//$users[$member_id]['channels'] = array(0);
   
}
}

// Sample user:
$users
[9999999] = array();
$users
[9999999]['userRole'] = AJAX_CHAT_USER;
$users
[9999999]['userName'] = 'user';
$users
[9999999]['password'] = 'user';
$users
[9999999]['channels'] = array(0,5);


Any possible houghts on the matter?  Or am I on my own to figure out since it's an antiquated CMS?  :)

Thanks again for any assistance you may be able to provide.




On Friday, May 2, 2014 9:47:59 PM UTC-4, Jeremy wrote:

Frug

unread,
May 6, 2014, 4:11:56 PM5/6/14
to ajax...@googlegroups.com
OH my god google groups stop sucking


On Friday, 2 May 2014 11:37:53 UTC-4, Jeremy wrote:

 
case 2<span
...

Frug

unread,
May 6, 2014, 4:12:35 PM5/6/14
to ajax...@googlegroups.com
" 3 strict messages about the date() function and timezones"



I think know this issue if it's complaining about your default timezone not being set. It's pointless and annoying, scripts will run fine if you ignore it for the most part. Your server needs to set its timezone in their php.ini. Google the error and you can find solutions to it. If you're on a shared host that uses cpanel, there's a place in your options somewhere to specify a timezone. Otherwise you'll have to set it in php.ini or in your scripts.


$rowv = mysqli_fetch_array($sqlresult2);  //Not sure about this row yet
    $rank_value
= $rowv["rank_value"];  //Not sure about this row yet



Your code looks like a mixture of the old procedural style, and the "new" object oriented style, and I wouldn't advise that. I have no idea how it works. The old way uses mysqli_connect(), mysqli_query(), mysqli_whatever(). The new way creates an object like this:

$connection
= new mysqli('localhost', 'my_user', 'my_password', 'my_db');

if ($connection->connect_error) {
   
die('Connect Error (' . $connection->connect_errno . ') ' . $connection->connect_error);
}



And then uses $connection->query()  and $connection->fetch_assoc()

Stick to one style (the new way). See the examples here: http://www.php.net/manual/en/mysqli.construct.php and look at http://ca2.php.net/mysqli_fetch_assoc

The examples should make it clear.




On Friday, 2 May 2014 11:37:53 UTC-4, Jeremy wrote:

 
case 2<span
...

Jeremy

unread,
May 8, 2014, 8:58:18 AM5/8/14
to ajax...@googlegroups.com
Thanks for the information and all of your assistance.  It is greatly appreciated.  Looks like I have a lot of catching up to do :)
Reply all
Reply to author
Forward
0 new messages