Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
error message

Posted by bschultz (bschultz), 1 May 2003
I'm trying to modify my sql db's since I had to move to a new ISP, and am no longer using my own server, and I'm having a problem writing to the db.

Here's the error message I'm getting:
1044: Access denied for user: '@localhost' to database 'bschultz_bgolf'

Here's the section of code I'm using:

Code:
<?php
if ($submit == "click"){
// The submit button was clicked!
// Get the input for the game then store it in the database.
if (! $db = mysql_connect("localhost", "my-user-name", "my-password")) die ("Unable to connect");
}  
$query = "insert into game6 values
('$score','$T1', '$T2', '$T3', '$T4', '$T5', '$T6', '$T7', '$T8', '$T9', '$T10',
'$T11', '$T12', '$T13', '$T14', '$T15', '$T16', '$T17', '$T18', '$T19', '$T20',
'$T21', '$T22', '$T23', '$T24', '$T25', '$T26', '$T27', '$T28', '$T29', '$T30',
'$T31', '$T32', '$T33', '$T34', '$T35', '$T36', '$T37', '$T38', '$T39', '$T40',
'$T41', '$T42', '$T43', '$T44', '$T45', '$T46', '$T47', '$T48', '$T49', '$T50',
'$T51', '$T52', '$T53', '$T54', '$T55', '$T56', '$T57', '$T58', '$T59', '$T60',
'$T61', '$T62', '$T63', '$T64', '$T65', '$T66', '$T67', '$T68', '$T69', '$T70',
'$T71', '$T72', '$T73', '$T74', '$T75', '$T76', '$T77', '$T78', '$T79', '$T80',
'$T81', '$T82', '$T83', '$T84', '$T85', '$T86', '$T87', '$T88')";
$result = mysql_db_query ("bschultz_bgolf", $query);
if ($result){
 echo "Thanks for your time, and good luck this season!";
}
else{
 echo mysql_errno().": ".mysql_error()."<BR>";
}
mysql_close ();
?>




ANy ideas what I'm doing wrong...the only thing I thought I had to change was the table name, to add the 'bschultz_" to it, which my new host requires...but it doesn't appear to me by the " '@localhost' that there is a username being used.

Thanks

Brian


Posted by admin (Graham Ellis), 1 May 2003
It looks like you have a permissions problem with the database - you're logging in OK but aren't able to use bschultz_golf.  First test  to confirm this is the case -  replace your call to mysql_db_query with a call to mysql_select_db followed by a call to mysql_query, and check that the error now occurs in the mysql_select_db.  By the way - mysql_db_query has been deprecated since 4.0.6, so the change should be left in  

If it does turn out that the error is in the selection of the database, have a careful look at the ISP's documentation or contant them and ask;  if they allow ANY database starting with your account name, it may well be that they have to create it themselves for you, or they have a special script to do so and to add access permissions for you to that new database.

Posted by bschultz (bschultz), 1 May 2003
I replaced "mysql_db_query with mysql_select_db and got this error message:

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/bschultz/public_html/warriors/sports/bgolf/results/secure/dates/game1.php on line 18


As for the db starting with a user name, I've created the db with their cpanel script (the only way to create a db) and it automatically puts the username in front of it...there's no way around that.

On a side note, I've dumped the db's from my server to their server, and the script that calls the db info in the php pages are working fine...it's just the script to write the info to the db that isn't working right.

Brian

Posted by admin (Graham Ellis), 1 May 2003
What are the parameter(s) that you're passing to mysql_select_db?   It doesn't like the second one. which should be the variable returned by the mysql_connect - i.e. $db in this instance.  You aren't passing the query in as the second parameter by any chance are you??

Posted by bschultz (bschultz), 2 May 2003
I just re-did the entire script and it works now...thanks Graham.

For those of you wondering, here's the new script:

Code:
<?
$DBhost = "localhost";
$DBuser = "my-user-name";
$DBpass = "my-password";
$DBName = "my-database-name";
$table = "my-table-name";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select
database $DBName");

$sqlquery = "INSERT INTO $table
VALUES('$score','$T1', '$T2', '$T3', '$T4', '$T5', '$T6', '$T7', '$T8', '$T9', '$T10',  
'$T11', '$T12', '$T13', '$T14', '$T15', '$T16', '$T17', '$T18', '$T19', '$T20',  
'$T21', '$T22', '$T23', '$T24', '$T25', '$T26', '$T27', '$T28', '$T29', '$T30',  
'$T31', '$T32', '$T33', '$T34', '$T35', '$T36', '$T37', '$T38', '$T39', '$T40',  
'$T41', '$T42', '$T43', '$T44', '$T45', '$T46', '$T47', '$T48', '$T49', '$T50',  
'$T51', '$T52', '$T53', '$T54', '$T55', '$T56', '$T57', '$T58', '$T59', '$T60',  
'$T61', '$T62', '$T63', '$T64', '$T65', '$T66', '$T67', '$T68', '$T69', '$T70',  
'$T71', '$T72', '$T73', '$T74', '$T75', '$T76', '$T77', '$T78', '$T79', '$T80',  
'$T81', '$T82', '$T83', '$T84', '$T85', '$T86', '$T87', '$T88')";

$results = mysql_query($sqlquery);

 if ($results){
   echo "Thanks for your time, and good luck this season!";
 }
 else{
   echo mysql_errno().": ".mysql_error()."<BR>";
 }
 mysql_close ();
?>



Thanks, again, Graham.  You are a life-saver.

Brian



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho