sineadyd Posted April 24, 2008 Share Posted April 24, 2008 Hi, Can anyone spot errors that I may have missed here because its really annoying me!I have a "users" db and tables for "admin","members" and "register" in it.I will only be using members and admin for this script, but whatever it is, it just will not connect to the database. any help would be really reeeeeally appreciated! Thanks in advance! <?php //Users Database settings $host="localhost"; $username="root"; $password=""; $db_name="users"; //connect to server $link = @mysql_connect ("localhost", "root", "password") or die ("Could not connect to localhost! Error: ".mysql_error()); @mysql_select_db($db_name, $link) or die("Could not connect to database! Error: ".mysql_error()); //create and issue the query $username=$_POST['USERNAME']; $password=$_POST['PASSWORD']; $sqlmemb="SELECT * FROM members WHERE username = '$username' and password='$password'"; $resultmemb= mysql_query($sqlmemb) or die(mysql_error()); //get the number of rows in the result set //should be 1 if theres a match $isset1=mysql_num_rows($resultmemb); $sqlamin="SELECT * FROM admin WHERE username='$username' and password='$password'"; $resultadmin= mysql_query($sqlamin) or die(mysql_error()); //get the number of rows in the result set // should be 1 if theres a match $isset2=mysql_num_rows($resultadmin); //------------// //member login// //------------// //If isset1(members login) is equal to 1 then the members homestart page is opened. if($isset1==1) { ?> <script language="javascript"> window.open('../www/homestart.htm','', config='scrollbars=yes,menubar=no,height=850,width=955,resizable=yes,status=yes')</script> <?php //create display string $display_block=" <p> ".$username." is authorised!</p>"; include 'Login.html'; } //-----------// //admin Login// //-----------// else if ($isset2==1) //If admin details are correct then it will open the administrators homestart page is opened. { ?> <script language="javascript"> window.open('../admin/homestart.htm','', config='scrollbars=yes,menubar=no,height=850,width=955,resizable=yes,status=yes')</script> <?php //create display string $display_block=" <p> ".$username." is authorised!</p>"; include 'Login.html'; } //------------// //Redirection// //-----------// else if ($isset1==0 OR $isset2==0)//If the username enters wrong details then an error is displayed { // and they are redirected back to the login page. echo '<html>'."n".'<body><div class="disfunction">Sorry, the Username and password you have entered are incorrect!</div></body>'."n".'</html>'; include 'Login.html'; exit; } //set authorisation cookie //setcookie("auth", "1", 0, "/","Login.html", 0); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>login.php</title> </head> <body> <?php echo "$display_block";?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/ Share on other sites More sharing options...
Xoom3r Posted April 24, 2008 Share Posted April 24, 2008 //connect to server $link = @mysql_connect ("localhost", "root", "password") or die ("Could not connect to localhost! Error: ".mysql_error()); @mysql_select_db($db_name, $link) or die("Could not connect to database! Error: ".mysql_error()); Delete "password"? Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525963 Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 //connect to server $link = @mysql_connect ("localhost", "root", "password") or die ("Could not connect to localhost! Error: ".mysql_error()); @mysql_select_db($db_name, $link) or die("Could not connect to database! Error: ".mysql_error()); Remove the @ symbols, so you can see any error messages http://phpsnips.com/snippet.php?id=18 Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525970 Share on other sites More sharing options...
sineadyd Posted April 24, 2008 Author Share Posted April 24, 2008 Im still getting the same error...."Access denied for user 'root'@'localhost' (using password: NO)" Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525972 Share on other sites More sharing options...
sineadyd Posted April 24, 2008 Author Share Posted April 24, 2008 after removing the running without error symbol '@' I have these errors: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in C:\wamp\www\LOGIN\login.php on line 9 Could not connect to localhost! Error: Access denied for user 'root'@'localhost' (using password: NO) Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525975 Share on other sites More sharing options...
jonsjava Posted April 24, 2008 Share Posted April 24, 2008 if you error has always been "access denied for user 'root'@'localhost' (using password: NO)" or "access denied for user 'root'@'localhost' (using password: YES)", then the issue is your password. Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525981 Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 $password=""; You have that empty... are you sure there is no password to the database? Are you running on your home computer or a remote web host? Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525983 Share on other sites More sharing options...
sineadyd Posted April 24, 2008 Author Share Posted April 24, 2008 Im running in on my own laptop.But if Ive no password set for localhost then that cant be it cud it?Do server apps require u to set a localhost pw? Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525986 Share on other sites More sharing options...
The Little Guy Posted April 24, 2008 Share Posted April 24, 2008 How did you create the tables? Try this: $link = @mysql_connect ("localhost", "root") or die ("Could not connect to localhost! Error: ".mysql_error()); @mysql_select_db($db_name, $link) or die("Could not connect to database! Error: ".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-525996 Share on other sites More sharing options...
sineadyd Posted April 24, 2008 Author Share Posted April 24, 2008 I created them through //localhost/phpmyadmin.Tried the code you suggested and still no luck is there any way I can check to see if there was a default password for localhost?Or any way I can recreate localhost andcorresponding pw and if so which database should I put it in? Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-526004 Share on other sites More sharing options...
mofm Posted April 24, 2008 Share Posted April 24, 2008 i agree with teh above post its a mysql authorization problem set yourself up a user name and password teh best way to do this is get php myadmin if you dont allready. all you have to do it extract it in ur sever root. and the go to its Directory in ur web broowser ie : http://localhost/phpmyadmin/ then change <?php //Users Database settings $host="localhost"; $username="root"; $password=""; $db_name="users"; to somthing like this <?php //Users Database settings $host="localhost"; $username="mysetusername"; $password="mysetpassword"; $db_name="users"; Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-526006 Share on other sites More sharing options...
sineadyd Posted April 24, 2008 Author Share Posted April 24, 2008 Should I set that up in the sql database on the localhost/phpmyadmin directory or in all of the db's ive created? Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-526012 Share on other sites More sharing options...
Fitzlegend Posted April 24, 2008 Share Posted April 24, 2008 Go into php myadmin and your database and click on privileges at the top. Give yourself a new username and password, full access etc. Then try the new name pass and use localhost as the host. Link to comment https://forums.phpfreaks.com/topic/102715-script-for-login-problem/#findComment-526081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.