SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why is this loop blowing up?

    I have the following code. What I'm trying to make it do is create a table that shows all the usersnames in this databases, and display each username in a seperate row of a table. Then I'm wanting to have different columns in that row, and display variables which are numbers in the database for each individual added together. I tried using the following code but I get the error message:

    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


    PHP Code:
    <?php
    mysql_connect
    ($db_host$db_user$db_pwd); 

    mysql_select_db($db_name); 

    $sql "SELECT * FROM authorize AS u_one INNER JOIN authorize AS u_all ON u_all.department IN ( u_one.department , u_one.department2 , u_one.department3 , u_one.department4 , u_one.department5 , u_one.department6 ) WHERE u_one.username = '$_SESSION[user_name]' AND NOT u_all.lockedstatus = 'LOCKED'"
    $result mysql_query($sql); 
    while(
    $row mysql_fetch_array($result))
      {
    echo 
    '<tr><td>' username'</td><td> <tr><td>' $total '</td><td>';  
      
      }

    mysql_close($con);
    ?>

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    well clearly you are trying to use a socket to connect to the MySQL server which does not allow that means to connect.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    logic_earth, I'm sorry but I have no idea what you mean by that.

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That error means that the script can't connect to your database. Do you have those variables at the beginning of the script defined somewhere? Those are used to connect to the db.
    I'm talking about this line:
    PHP Code:
    mysql_connect($db_host$db_user$db_pwd); 

  5. #5
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, They are in my script at the heading.

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Are you sure that they're correct?

    Apart from that, I can tell you that the following line is incorrect:
    PHP Code:
    echo '<tr><td>' username'</td><td> <tr><td>' $total '</td><td>'
    Try:
    PHP Code:
    echo '<tr><td>' $row['username']. '</td><td> <tr><td>' $row['total'] . '</td><td>'
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still get same error

    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

  8. #8
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cd /usr/local/mysql
    ./bin/mysqld_safe --user=mysql &

  9. #9
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    What is contained in "$db_host".

    I also told you the problem you cannot connect to the mysql database using sockets.

    hence the error message " Can't connect to local MySQL server through socket"
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  10. #10
    SitePoint Guru
    Join Date
    Oct 2006
    Location
    Queensland, Australia
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    Are you sure that they're correct?

    Apart from that, I can tell you that the following line is incorrect:
    PHP Code:
    echo '<tr><td>' username'</td><td> <tr><td>' $total '</td><td>'
    Try:
    PHP Code:
    echo '<tr><td>' $row['username']. '</td><td> <tr><td>' $row['total'] . '</td><td>'
    What's with the <tr> tags? for example...

    <tr><td>data1</td><td><tr><td>data2</td><td>

    That's not a valid table row. You can't have <tr> tags directly under <td> tags. Not only that, but the rest of your table is a mess also (not you arkinstall, although your 'fix' still includes the table problems, hence the quote).

  11. #11
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    not sure about the socket thing but have you defined the variables

    $db_host = 'localhost';
    $db_user = 'me';
    $db_pwd = 'mypass';

  12. #12
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've defined my variables. I'm still having thesee problems

  13. #13
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,198
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    As logic_earth has mentioned two times already, the problem is that you can not connect to a mysql server at the address you have given it.

    This either means that there is no mysql server at localhost, that it use a different socket filename than "localhost" or that you need to connect to it through TCP/IP.

    Check out the MySQL documentation for more information:
    http://dev.mysql.com/doc/refman/5.0/...to-server.html

  14. #14
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's no longer displaying the error:

    Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    However, it's not displaying any error or output at all. Just shows a blank page.

  15. #15
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I got the data to print out now. It's just not in table format it looks like a big paragraph of data.

  16. #16
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    username | Reg | O/T | Reg | O/T | Reg | O/T | Reg | O/T | Reg | O/T | Reg | O/T | Reg | O/T | Reg |O/T

    The above represents a row in the table the| starts a new column. That's how I need the data to be presented.


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
  •