FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


maybe i'm daft...





Kaze_Mitoki
Ok. here's my situation.

I've got a database set up with permissions for a few test usernames and passwords. I have code that is supposed to connect to that database and see if the username and password combination is correct, check permissions, and then go.

However, when trying to run that code, it keeps saying "access denied". I am not quite sure what to do.

I am using the PHP mysql_connect function. Heck, not even the default username/pass combo for that function will work! Below is the snipet of code affecting the connection:

Code:
//create DB handle, AKA connection
// if(!($connection = mysqli_connect('72.249.102.79','kazemito','pass','rosydata'))){
if(!($connection = mysql_connect('72.249.102.79','mysql.default_user' ))){
echo"<h1>There was an error connecting to the database.</h1>";
}//end DB handle creation if statement


and after that, this is the error I get...
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mysql.default_us'@'server.frihost.net' (using password: NO) in /home/kazemito/public_html/check_credentials.php on line 22


Maybe I'm daft or something, but I'm stumped. Could somebody please help me?
sonam
I am not sure but I think how you need in second line to remove // because php your if statment reading like comment.

Sonam
woodenbrick
Does the mysql.default_user have a password? Because you haven't set one.
mysqli_conect <- spelt incorrectly.
Why are you using one inside the other exactly?
Anyway just what i noticed, hope it helps in some way.
Kaze_Mitoki
To answer the questions posed...

line two is supposed to be a comment... Those are the settings I think -should- work, but for some reason they don't. so I copied and pasted right below there, and the one that is not commented out is the one that i'm experimenting with.

Thank you for noticing my misspelling. I"ll fix that now...

The default value has no password associated with it that I could find. I would have assumed it would be something simple, like the word "password" or something, but it's blank.

and, one inside the other? I'm not quite sure what you mean.
woodenbrick
I was just wondering why you chose to use mysqli for the first part and mysql for the second.
rvec
use this code:
Code:

$user = "your username here";
$pass = "your pass here";
$con = mysql_connect("localhost",$user,$pass);
if (!$con)
  {
  die('<h1>There was an error connecting to the database.</h1>' . mysql_error());
  }


If that doesn't work there is something wrong with the frihost server. Also make sure you have the exact same username and password as you typed in cpanel, it's case sensitive.
Kaze_Mitoki
Thank you for that. It worked, I now can establish a connection to my database. ^^

and to answer brick's question, I was experimenting. I know about mysql_connect, and mysqli_connect, and figured I would use whichever one I could get to work.

I am having other errors, but I am going to seek other documentation first... either way, my other problems, as they apear on my error page, are as follows:

ERROR SELECTING DATABASE!!

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/kazemito/public_html/check_credentials.php on line 38

Line 38:
Code:
if(!($result =mysql_query($con, $query))){


ERROR QUERYING MYSQL

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kazemito/public_html/check_credentials.php on line 43

Line 43:
Code:
if(mysql_num_rows($result) == 0){


Warning: Cannot modify header information - headers already sent by (output started at /home/kazemito/public_html/check_credentials.php:31) in /home/kazemito/public_html/check_credentials.php on line 45
Line 45:
Code:
header("Location:login.php?message=" . urlencode($_SESSION['message']) ."&uname" .urlencode($_SESSION[$usr]));
alalex
the problem is selecting the db,
use something like:
Code:
if(!mysql_select_db('nameOfDatabase')){ die(mysql_error()); }

Also make sure the database exists, and once that is corrected all other errors should dissapear.
The last one appears because you cannot modify headers after output is displayed, and in this case the output are the errors...

If you still get an error with the code above post it here and we'll see Wink
Kaze_Mitoki
Did that, and now the only thing I get on my screen when I try to run the thing is this:

Access denied for user 'kazemito'@'localhost' to database 'rosydata'

... I haven't changed anything else, I don't really understand...

and, if I haven't said anything until now, THANK YOU ALL for helping me out!! I have been trying to resolve this thing on my own for two weeks now...
rvec
Kaze_Mitoki wrote:
Did that, and now the only thing I get on my screen when I try to run the thing is this:

Access denied for user 'kazemito'@'localhost' to database 'rosydata'

... I haven't changed anything else, I don't really understand...

and, if I haven't said anything until now, THANK YOU ALL for helping me out!! I have been trying to resolve this thing on my own for two weeks now...

you sure you got the right password and username? Maybe try to login to phpmyadmin and see if you can login there. If you can there is something wrong in your script, if you can't you got the wrong pass/username/db.
Kaze_Mitoki
Yeah, I just logged into phpmyadmin with the same username/pass that I use in my script. and the database is there, I'm looking at it...

Meh, more puzzling to do. thank you all again for helping out.
alalex
im really confused about all this but maybe the host you are using is wrong... I remember in the first post you were using an ip, and maybe the ip is dynamic and so it changed...
Did you try connecting to 'localhost' because that might be the problem...
If your host is not localhost (in frihost it is) you could use phpmyadmin to look up the host name..

Just an idea Wink
sonam
Same problem I have last week on one other hosting and I am solve problem when I am look what is real name of my db (not what I mean). For examlple:

If you create new DB with MySql Database Wizad then you will type something like:
DB name : myDb
User : meandonlyme
Password : something

Now if you want to see real name of DB and real User name you need to open MySQL Databases. There you will see how your DB name and User name get your account name in the front. For example:
sonam_myDB
sonam_meandonlyme

This is what I am use for php connecting and I got connection without any problem.

Sonam
Kaze_Mitoki
I am connecting using "localhost" so I didn't change any of that.

I did put the prefix onto my database and username, and now it's connecting quite nicely. However, I now get -this- across my screen:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/kazemito/public_html/check_credentials.php on line 36

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kazemito/public_html/check_credentials.php on line 41

Warning: Cannot modify header information - headers already sent by (output started at /home/kazemito/public_html/check_credentials.php:36) in /home/kazemito/public_html/check_credentials.php on line 43

Line 36 is the line that runs a query though the database connection. I am storing my query in a variable called $query. and this is what is stored in that variable:

Code:
$query = "SELECT usr, pass FROM usr_tbl WHERE usr='" . $_SESSION[$usr] ."'";


That was line 33... line 36 is:

Code:
if(!($result=mysql_query($con, $query))){


EDIT:

I checked to make sure all of my table names and fields matched what I was looking for, and they did not. I fixed it, but i'm still getting the text in red.

EDIT #2:

Did some research on my own and found that problem. and now i'm having a different situation altogether.

I'm using sessions to keep my pages secure. but the sessions aren't working propperly - I've logged in as my test user and i can view them, but I can also view them when i'm logged out (which calls session_destroy() )

help?
rvec
it's a bit hard to solve a problem if you don't have the full code.

Could you change the pass and username and put it in a zip file or something, I'll take a look at the full code if you do.
Kaze_Mitoki
Look for a PM in your box, rvec.
DoctorBeaver
I had a similar problem that was driving me crazy. In the end I retrieved the record matching the username and used trim() on both the password that had been input AND on the field I retrieved from the DB, then did a compare. That worked.
Related topics
I have a problem....Mozilla Firefox
Coldplay
Anyone?
Maybe
MP3 UPLOADING!
Cpanel for Plesk users?
How do you keep the CD-Drive from making too much noise.
was Hitler a Christian?
IP for Virtual domain
Scripting Admin Needed
starting a business (leagal maybe) help.
Illusion & Dream
Maybe we should.....
JavaScript or Java Applet and maybe DHTML codes
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.