PHP pain.

Discussion in 'PHP' started by SirChronos, Nov 7, 2007.

  1. #1
    Upon connecting to myqsl database...tadaaa:

    Everything in my config.php is correct, yet this still occurs. I've looked around the net and haven't found the solution yet >_>

    I'll even show you my code.

    open_db.php:
    <?php
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

    mysql_select_db($dbname);
    ?>

    close_db.php:
    <?php
    mysql_close($conn);
    ?>

    config.php:
    <?php
    $dbhost = 'mysql4.freehostia.com';
    $dbuser = 'robste332';
    $dbpass = 'lkv81';
    $dbname = 'robste332_dtb';
    ?>

    test_db.php:
    <html>
    <head>

    <title>Revelations of the Ancients</title>
    <meta name="Keywords,XRealms,X-Realms" content="game" />
    <link rel="stylesheet" type="text/css" href="theme.css" />

    </head>
    <body>

    <?php
    include 'config.php';
    include 'open_db.php';

    $query = "SELECT name, subject, message FROM contact";
    $result = mysql_query($query);

    while(list($name,$subject,$message)= mysql_fetch_row($result))
    {
    echo "Name :$name <br>" .
    "Subject : $subject <br>" .
    "Message : $row <br><br>";
    }

    include 'close_db.php';
    ?>

    </body>
    </html>
     
    SirChronos, Nov 7, 2007 IP
  2. ForgottenCreature

    ForgottenCreature Notable Member

    Messages:
    7,473
    Likes Received:
    173
    Best Answers:
    0
    Trophy Points:
    260
    #2
    You should edit your post - and remove your db's password.
    Change your dbhost to localhost
     
    ForgottenCreature, Nov 7, 2007 IP
  3. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Agreed,but change to "localhost" AFTER changing your database password !
     
    Amilo, Nov 7, 2007 IP
  4. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #4
    That advice may NOT be correct if they are using a seperate mysql server as many hosts now do that.

    Is this a cPanel server? If so the correct format for the database name and username is cpanelusername_databasename cpanelusername_username

    Post again with more info.
     
    Colbyt, Nov 7, 2007 IP
  5. SirChronos

    SirChronos Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I've tried it without the pass, with the cpanel stuff (I am guessing I'm not using cpanel), I've checked the username, database name, password and host several times and they are all correct as far as I know.

    And... that isn't my real db pass =P

    By the way I'm using freehostia
     
    SirChronos, Nov 7, 2007 IP
  6. DooBDee

    DooBDee Active Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #6
    Could i clarify one thing? Why is the error message and the parameters in that message not inline with your configuration file? Is that because you changed it for DP?

    Cheers
     
    DooBDee, Nov 7, 2007 IP
  7. SirChronos

    SirChronos Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes that's right DooBDee. I found the problem...the dbuser is supposed to be the same as the dbname (with some help from tech support). But...now I have another problem. I get this message:
    I have a sutle idea of what it means, but I'm still too new to PHP to locate the problem.
     
    SirChronos, Nov 7, 2007 IP
  8. DooBDee

    DooBDee Active Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #8
    Hi,

    Firstly, I would use this code:
    while ($row = mysql_fetch_assoc($result))
    {
        echo $row['name'];
        echo $row['subject'];
        echo $row['message'];
    }
    PHP:
    If the problem persists then there is problem with your select statement (not right table etc...).
     
    DooBDee, Nov 7, 2007 IP
  9. SirChronos

    SirChronos Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Uh, well, I know no more about sql than php...I'm researching though.

    And that code produces another error. I feel it's sql related.
    Edit: I know how to gather stuff via query, but I just want to draw info for only so many lines. I wouldn't need a query for that would I? Oh, wait, this is the PHP section isn't it...sorry.
     
    SirChronos, Nov 7, 2007 IP
  10. garbageman

    garbageman Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The "not valid result" part means your resource is bad, i.e. the query returned 0 rows. Check your query to make sure it responded.
    
    mysql_query($sql) or die(mysql_error());
    
    PHP:
     
    garbageman, Nov 7, 2007 IP
  11. DooBDee

    DooBDee Active Member

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    86
    #11
    Problem definately lies your SELECT. Are you selecting valid fields, tables etc...? Make sure everything matches.
     
    DooBDee, Nov 7, 2007 IP
  12. Amilo

    Amilo Peon

    Messages:
    624
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Remember that php helps you by showing you the line that it falls over at.

    Check line 33 of your test_db.php file.

    Can you paste your query for us ?
     
    Amilo, Nov 8, 2007 IP
  13. CEHonline

    CEHonline Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    and the host in mysql is %?
     
    CEHonline, Nov 9, 2007 IP
  14. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #14
    I just hope that before he learns anything, he had changed the account to his db, otherwise some dubious individuals might do some well, dubious things :p
     
    serialCoder, Nov 9, 2007 IP