Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP/MySQL Problem

    Im am trying to write a PHP script that will connect to a mysql database. So far I have made two files: post.html, and connect.php. post.html is the file I have made that has a form in it. the form is supposed to "post" MySQL login information to config.php.

    when i submit the login information to config.php i get this error message:

    Warning: mysql_connect(): Access denied for user: 'mydatabase@localhost' (Using password: YES) in /home2/goobers/public_html/php2/config.php on line 10
    here is the coding i used for config.php:

    PHP Code:
    <?php

    // MySQL Login Information 

    $db_username   =  $_POST['db_name'];   // Database Username
    $db_password   $_POST['db_password'];  // User Password
    $db_name  $_POST['db_name'];   // Database Name
    $db_host  $_POST['db_host'];  // This will usually be localhost

    $link mysql_connect ("$db_host""$db_username""$db_password");

    mysql_select_db ('$db_name')

    ?>
    What do I do to fix this problem?
    Last edited by Goober; 12-13-2003 at 10:01 PM.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Usually means your password is wrong

  • #3
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    umm, I made sure I entered all the correct login information. I think my problem has to do with the coding. possibly it has to do with the other file i made, post.html. (though I could be wrong)

    here is the coding i used for post.html:
    (And incase it helps here is a link the the actual file: http://www.thegoobers.com/php2/post.html)

    Code:
    <form action="config.php" method="post">
    <table border="0" cellspacing="0" cellpadding="10" class="form">
    
    <tr>
    <td align="left">Database Username:</td>
    <td><input class="input" type="text" name="db_name"></td></tr>
    
    <tr>
    <td align="left">Database Password:</td>
    <td><input class="input" type="password" name = "db_password"></td></tr>
    
    <tr>
    <td align="left">Database Host:</td>
    <td><input class="input" type="text" name="db_host" value="localhost"></td></tr>
    
    <tr>
    <td align="left">Database Name:</td>
    <td><input class="input" type="text" name="db_name"></td></tr>
    <tr><td align="center" colspan="2"><input type="submit" value="Submit" class="button">
    </td></tr>
    
    </table>
    </form>
    what is the error I made? and what file is it in?
    Last edited by Goober; 12-13-2003 at 09:52 PM.

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You've got:

    $db_username = $_POST['db_name']; // Database Username

    $db_name = $_POST['db_name']; // Database Name


    Unless you named the user the same as your db, i'd say that this is you first problem.

    Also; drop the intermediate variables and include the $_POST-variables directly inside the mysql-function
    Also: drop the quotes around the variables inside the mysql-functions
    Also: open a persistent connection with mysql_pconnect

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why do you suggest a persistent connection, if u dont mind me asking?
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by ReadMe.txt
    why do you suggest a persistent connection, if u dont mind me asking?
    like the name says, pconnect opens a persistent connection that remains open after the script has executed, until the timout is reached.
    If a new connection is needed in a later script, then the webserver will first look for an already open connection and wount open a new one.

    So it's mainly a timesaver.

    The possible downside, if you son't set the timoutparameter right(inside your mysql config file; my.cnf), is that you have a number of unused, open connection, which will only consume memory-resources.

    But if you have substantial db-trafic on your site (high number of simultanious users or lots of querys inside your pages) then you best use pconnect and plug in a bit of extra memory.
    If this doesn't have i significant performance gain or if this takes up more memoryresources then you like, then you can still remove the 'p' inside your connectionfile.
    For hosted sites, i always use pconnect. Never had any complaint from host that i was eating up to much memory. (If they do their job properly, they'll set a low number of persistent connections and low timoutvalues indide the my.cnf)

    Note : for webservers like IIS, pconncect or connect behave the same.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •