CitiZen Posted October 27, 2004 Posted October 27, 2004 Hi, I'm tryin' to use a mod that I was using "successfully" at another Web host, but all I get are errors. Anyone have an idea? Thanks Here's the effected part of the code: Warning: mysql_connect(): Access denied for user: 'database_username@localhost' (Using password: YES)in /home/username/public_html/admin/new_orders.php on line 39 Unable to connect to MySQL <?php $hostname = "localhost"; $username = "correct_database_username"; $password = "correct_database_password"; $database = "correct_database_name"; $dbh = mysql_connect($hostname,$username,$password) <--This is line 39! or die("Unable to connect to MySQL"); $selected = mysql_select_db($database,$dbh) or die("Could not select first_test"); $result = mysql_query("SELECT * FROM `orders` WHERE orders_status = '1'"); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { // echo "<br>ID:".$row{'orders_id'}; $ordernummer = $row{'orders_id'}; // Query de order $resultaat2 = mysql_query("SELECT * FROM `orders_products` WHERE orders_id = $ordernummer"); while ($row2 = mysql_fetch_array($resultaat2,MYSQL_ASSOC)) { ?> or $dbh = mysql_connect('$hostname,$username,$password') Warning: mysql_connect(): Unknown MySQL Server Host '$hostname,$username,$password' (1) in /home/username/public_html/admin/new_orders.php on line 39Unable to connect to MySQL Quote
TCH-Dick Posted October 27, 2004 Posted October 27, 2004 Well the first question would be, did you fill in the correct info for database username, password and database name? They should be cpanelname_username, password and cpanelname_database. If you did that, the next question would be did you create the user and assign it to the database in managemysql in cpanel? If you already did both of those i'm stumped Quote
LisaJill Posted October 27, 2004 Posted October 27, 2004 Go to mysql manager and choose the database and user and click "Add user to database" - you should then see a bunch of MySQL connection strings - then try again. That's the most common cause anyway. =) Quote
CitiZen Posted October 28, 2004 Author Posted October 28, 2004 Yes, of course I added a user: cpanelname_dbusername (Privileges: ALL PRIVILEGES)<-- But, I still get this error. Warning: mysql_connect(): Access denied for user: 'cpanelname_dbusername@localhost' (Using password: YES) in /home/cpanelname/public_html/admin/new_orders.php on line 39 Unable to connect to MySQL I've tried to chmod the file 777, 666, 644 and still the same message. Quote
CitiZen Posted October 28, 2004 Author Posted October 28, 2004 I've also tried the suggested code in the MYSQL Cpanel area, but I get the same error. <?php$dbh=mysql_connect("localhost", "cpanelname_dbusername", "dbusername_password") or die("Unable to connect to MySQL");<--MYSQL Cpanel area code $selected = mysql_select_db("cpanelname_dbname") or die("Could not select first_test"); $result = mysql_query("SELECT * FROM `orders` WHERE orders_status = '1'"); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { // echo "<br>ID:".$row{'orders_id'}; $ordernummer = $row{'orders_id'}; // Query de order $resultaat2 = mysql_query("SELECT * FROM `orders_products` WHERE orders_id = $ordernummer"); while ($row2 = mysql_fetch_array($resultaat2,MYSQL_ASSOC)) { ?> Quote
jandafields Posted October 28, 2004 Posted October 28, 2004 Yes, of course I added a user: But did you add the user to the database? After creating the user, the user must be added to the database... Quote
CitiZen Posted October 31, 2004 Author Posted October 31, 2004 Hi jandafields, Yes I have. It is the same info I use for accessing the osCommerce database, which is working fine. So, I don't know why this code would not work as well? Maybe someone will spot something I missed! Thanks Here is the full code: <?php<font face="verdana" size="5"><center>New Orders<br><br></center><font size="3"> <table style="BORDER-COLLAPSE: collapse" borderColor="#666666" cellSpacing="1" borderColorDark="#aaaaaa" cellPadding="4" width="90%" align="center" borderColorLight="#aaaaaa" border="1"> <body bgcolor="#ffffff"><font face=verdana> <tr> <td class="px8" borderColorLight="#aaaaaa" width="10%" bgColor="#efefef" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="2"><b>Order Number</td> <td class="px8" borderColorLight="#aaaaaa" width="10%" bgColor="#efefef" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="2"><b>Model</td> <td class="px8" borderColorLight="#aaaaaa" width="40%" bgColor="#efefef" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="2"><b>Description</td> <td class="px8" borderColorLight="#aaaaaa" width="10%" bgColor="#efefef" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="2"><b>Price</td> <td class="px8" borderColorLight="#aaaaaa" width="5%" bgColor="#efefef" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="2"><b>Qty.</td> <td class="px8" borderColorLight="#aaaaaa" width="25%" bgColor="#efefef" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="2"><b>Comments</td> </tr> <?php $hostname = "localhost"; $username = "cpanelname_dbusername"; $password = "dbusername_password"; $database = "cpanelname_dbname"; $dbh=mysql_connect($hostname,$username,$password) or die("Unable to connect to MySQL"); $selected = mysql_select_db($database,$dbh) or die("Could not select first_test"); $result = mysql_query("SELECT * FROM `orders` WHERE orders_status = '1'"); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { // echo "<br>ID:".$row{'orders_id'}; $ordernummer = $row{'orders_id'}; // Query de order $resultaat2 = mysql_query("SELECT * FROM `orders_products` WHERE orders_id = $ordernummer"); while ($row2 = mysql_fetch_array($resultaat2,MYSQL_ASSOC)) { ?> <tr> <td class="px8" borderColorLight="#aaaaaa" width="10%" bgColor="#ffffff" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="1"><?php echo $ordernummer; ?></font></td> <td class="px8" borderColorLight="#aaaaaa" width="10%" bgColor="#ffffff" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="1"><?php echo "".$row2{'products_model'}; ?></font></td> <td class="px8" borderColorLight="#aaaaaa" width="40%" bgColor="#ffffff" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="1"><?php echo "".$row2{'products_name'}; ?></font></td> <td class="px8" borderColorLight="#aaaaaa" width="10%" bgColor="#ffffff" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="1"><?php echo "".$row2{'products_price'}; ?></font></td> <td class="px8" borderColorLight="#aaaaaa" width="5%" bgColor="#ffffff" borderColorDark="#aaaaaa" height="25" align="center"><font face="verdana" size="1"><?php echo "".$row2{'products_quantity'}; ?></font></td> <td class="px8" borderColorLight="#aaaaaa" width="5%" bgColor="#ffffff" borderColorDark="#aaaaaa" height="25"><font face="verdana" size="1"></td> </tr> <?php } } mysql_close($dbh); ?> </font></table> Quote
TCH-Don Posted October 31, 2004 Posted October 31, 2004 (edited) $password = "dbusername_password"; This is just a password right? not user and password I am sure you are, but just checking Edited October 31, 2004 by TCH-Don Quote
jandafields Posted October 31, 2004 Posted October 31, 2004 $password = "dbusername_password";This is just a password right? not user and password I am sure you are, but just checking That gets me a lot. I have to remember that the database_name and the user_name both have the cpanel_id in front of them, but the password has nothing in front of it. Other than that, your connection string looks correct... Quote
CitiZen Posted November 2, 2004 Author Posted November 2, 2004 Hi TCH-Don, Sorry about that, typo. Yes ONLY the password is there. Thanks I've given up on trying to get this to work , so to everyone thanks for the input. Quote
carbonize Posted March 27, 2005 Posted March 27, 2005 I know it's a bit late now but I had this problem. I found that you have to add the user and then once you get the user listed where you get User: <dropdownlist> Db: <dropdownlist> you have to click the Add user to Db button. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.