Forum Moderators: coopster

Message Too Old, No Replies

database does not connect to my php interface

         

lindaonline15

8:28 am on Mar 24, 2010 (gmt 0)

10+ Year Member



dear all,
hi,
im currently using a php for interface and WAMP for the server side which uses phpMyAdmin.
this is a e-dentistry that I got from my friend to implement in my laptop.
for some reason, which i dont know what it is, after I imported all database, I've changed the database user and password, etc... when I want to login in the first place, I get this errors:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\ITProject\SE2Project\Edentistry\loginp.php on line 13
Could not connect
Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\wamp\www\ITProject\SE2Project\Edentistry\loginp.php on line 16

Warning: mysql_query() [function.mysql-query]: Access denied for user 'SYSTEM'@'localhost' (using password: NO) in C:\wamp\www\ITProject\SE2Project\Edentistry\loginp.php on line 17

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\wamp\www\ITProject\SE2Project\Edentistry\loginp.php on line 17

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\ITProject\SE2Project\Edentistry\loginp.php on line 18

Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\ITProject\SE2Project\Edentistry\loginp.php on line 19

=============================================================================================

and my login page code are:

$user=$_POST['user'];
$pass=$_POST['pass'];

$link=mysql_connect("127.0.0.1:3306","root","edentistry");
if (!$link)
echo "Could not connect";
mysql_select_db("edentistry",$link);
$result=mysql_query("SELECT * FROM user_pass WHERE user='$user' AND password='$pass'");
$row=mysql_fetch_assoc($result);
mysql_free_result($result);

if ($row['user']!="" && $row['password']!=""){
if($row['user'] == 'secretary')
include 'secretary.php';
else if ($row['user'] == 'dentist')
include 'dentist.php';
}
else
include 'invalid.php';


any idea to solve my problem? it is really urgent as I do not have sufficient time...
thanks

mack

8:38 am on Mar 24, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Did you get any errors when logging in using phpmyadmin?

Also you should be able to swap 127.0.0.1:3306 for localhost...

$link=mysql_connect("localhost","root","edentistry");

If you are getting errors using phpmyadmin confirm the mysql server is running. If there are no errors when using phpmyadmin double check your user pass fields.

Mack.

Matthew1980

11:07 am on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there lindaonline15,

Try this:-

$user = mysql_real_escape_string(strip_tags($_POST['user']));
$pass = mysql_real_escape_string(strip_tags($_POST['pass']));
//Used two functions there to protect the database from bad code injection ;-p

$SQLhost = "localhost";
$SQLuser = "root";
$SQLpass = "edentistry";

$link=mysql_connect($SQLhost, $SQLuser,$SQLpass) or die(mysql_error());

if (!$link){
echo "Could not connect";
exit;//kill script as there is no connection
}
else{
//Run the script, connection succesful

mysql_select_db("edentistry",$link) or die(mysql_error());

$result = mysql_query("SELECT * FROM `user_pass` WHERE `user` = '".$user."' AND `password` ='".$pass."'") or die(mysql_error());

$row = mysql_fetch_assoc($result);
mysql_free_result($result);

if ($row['user']!="" && $row['password']!="")
{
if($row['user'] == 'secretary')
{
include 'secretary.php';
}else if ($row['user'] == 'dentist')
{
include 'dentist.php';
}
else{
include 'invalid.php';
}
}//close main if/else

That should be Ok as far as getting the data is concerned, but make sure that the username and password is the same as when you log into phpmyadmin. If not the permissons havn't been set correctly and you will need to stipulate a passowrd for the root account (I think it's done via the privileges link/tab)

From what I could see, there were no braces encasing the if's and elseif's Whether that is acceptable I'm not sure that's just the way I code to avoid confusion ;-p

Cheers,
MRb

lindaonline15

3:32 pm on Mar 24, 2010 (gmt 0)

10+ Year Member



thanks all for helping me with this out. the problem was with the password, which previously I had change the password for root@localhost, then phpmyadmin suddenly prevented me from accessing, and at that time, I didnt check back for the login again because I was hurshing to find a way to get phpmyadmin back in the normal stage. then I reinstalled back phpmyadmin and it worked fine, but the login still the same.... after that, I posted this, I got ur replies and I tried them just now, I saw they did not work, then this time, intentially I changed the password for root@localhost of phpmyadmin again, and again it happened, it prevents me from accessing phpmyadmin, but i did this to check on the login and now I see it works! so my only problem is, where should I change the config of phpmyadmin to let me access with the new password coz previously the password for root@localhost was null by default but now I changed it to 'edentistry' and the pages work, but I can't access directly to phpmyadmin...

Matthew1980

3:42 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there lindaonline15,

There is a config file in the root install of phpmyadmin that has "default" settings in it. It will have something like username & password set up on (from memory) 2 different arrays, and then further down there is something called the blowfish_secret that is only to be filled in if you want the cookie set *again from memory*.

Hope this helps.

And At leat you got the script going! Cool..

Cheers,MRb

lindaonline15

3:58 pm on Mar 24, 2010 (gmt 0)

10+ Year Member



thank you very much matthew for all the help..
the problem is.. I cannot find the config file that has username and password in it.. i've looked through many files which are called config... or php.ini.... and many more
but none is about user and password :(

Matthew1980

4:05 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there lindaonline15,

It's in the root directory of your phpmyadmin install.

I think this is th structure of the tree, but its been a while since I looked ;-p

C:/wamp/phpmyadmin/

But its a .php file, I think it's something like: config_inc.php

I take it as you are locked out from phpmydamin then? There is a difference between phpmyadmin & phpmyadminlite too so see what version you have going.

It's there, just have to find it ;-p

Cheers,
MRb

rocknbil

7:41 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know **exactly** what is happening here, but let me share a couple things with you.

previously I had change the password for root@localhost, then phpmyadmin suddenly prevented me from accessing,


EDIT: note the exceptions, in your case, a local install. The first point is, you should never futz with the root mysql password unless you know what you are doing. This means, for most people, "never". :-) In your case, since it's a local install, set phpMyAdmin as user root, but don't use it for your scripts.

Note I am not advising against changing your phpMyAdmin pass, this is good and you should do it frequently. But use it **only** for phpMyAdmin.

This is the root of the problem (pun intended :-) ) in that you are trying to use user root for your scripts, breaking phpMyAdmin, and back and forth.

The second point is none of your applications should ever, ever run as root for mySQL. Create another user for your scripts, do not use root. Make it anything but root, make it hard to guess.

Set the pass for this user, then as M pointed out above, the problem was you are missing the user's password in the connection string.

$link=mysql_connect($SQLhost, $SQLuser,$SQLpass) or die(mysql_error());

lindaonline15

2:02 am on Mar 25, 2010 (gmt 0)

10+ Year Member



got the file ... its in: C:\wamp\apps\phpmyadmin3.2.0.1
called config.inc
changed the password and now everything is fine...


thanks all for helping :)

Matthew1980

8:39 am on Mar 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Lindaonline15,

Excellent! Well, as rocknbil points out for future projects/installs setting the root as the main passworded entry into your sql database in theory is a bad idea, though locally you should be ok, but for good practice, create another user account and set the priviledges up & password up for this new user, to pretty much mimic the setting's and permisson's (except DROP DATABASE, imo).

I use xammp, and I know that the directory architecture is quite similar to lammp as I tried lammp when I tried ubuntu for a few days (I'm windows, have been since 3.1, Old habits etc...)

For now though, happy coding!

Cheers,
MRb