sineadyd Posted April 23, 2008 Share Posted April 23, 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 and select database. mysql_connect("$host","$username","$password") or die("connection was unsuccessful"); mysql_select_db("db_name")or die("Database connection was unsuccessful"); //User database tables needed. $tbl_memb="members"; $tbl_admin="admin"; //create and issue the query $username=$_POST['USERNAME']; $password=$_POST['PASSWORD']; $sql1="SELECT * FROM members WHERE username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')"; $resultmemb= mysql_query($sqlmemb) or die(mysqli_error($mysql)); //get the number of rows in the result set; should be 1 if theres a match $isset1=mysql_num_rows($resultmembs); $sql2="SELECT * FROM admin WHERE username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')"; $resultadmin= mysql_query($sqladmin) or die(mysqli_error($mysql)); //get the number of rows in the result set; should be 1 if theres a match $isset2=mysql_num_rows($resultadmins); //------------// //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>'."nn".'</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>successlogin.php</title> </head> <body> <?php echo "$display_block";?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/ Share on other sites More sharing options...
schme16 Posted April 23, 2008 Share Posted April 23, 2008 Try fixing: "mysql_select_db("db_name")or die("Database connection was unsuccessful");" with: mysql_select_db($db_name)or die("Database connection was unsuccessful"); Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524892 Share on other sites More sharing options...
sineadyd Posted April 23, 2008 Author Share Posted April 23, 2008 Ok, I have no errors now but it still won't connect.DO ya think I've missed anything else? <?php //Users Database settings $host="localhost"; $username="root"; $password=""; $db_name="users"; //Connect to server and select database. mysql_connect("$host","$username","$password") or die("connection was unsuccessful"); mysql_select_db($db_name)or die("Database connection was unsuccessful"); //User database tables needed. // $tbl_memb="members"; // $tbl_admin="admin"; //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(mysqli_error($mysql)); //get the number of rows in the result set; should be 1 if theres a match $isset1=mysql_num_rows($resultmemb); $sqladmin="SELECT * FROM admin WHERE username='$username' and password='$password'"; $resultadmin= mysql_query($sqladmin) or die(mysqli_error($mysql)); //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>successlogin.php</title> </head> <body> <?php echo "$display_block";?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524912 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Change: mysql_connect("$host","$username","$password") or die("connection was unsuccessful"); To: $dbc = mysql_connect("$host","$username","$password") or die("connection was unsuccessful"); Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524917 Share on other sites More sharing options...
sineadyd Posted April 23, 2008 Author Share Posted April 23, 2008 No suck luck.......This is actually driving me mental cos Ive spent all friggin' day at it.Any other suggestions any1? Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524920 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 Do me a favor: Add this after the $dbc = mysql_connect(); line: if (is_null($dbc) && !(is_resource($dbc))) { die('Error getting connection.'); } Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524928 Share on other sites More sharing options...
sineadyd Posted April 23, 2008 Author Share Posted April 23, 2008 I just get an error: Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\LOGIN\login.php on line 27 //create and issue the query $username=$_POST['USERNAME']; $password=$_POST['PASSWORD']; $sqlmemb="SELECT * FROM members WHERE username = '$username' and password='$password'"; [b] Line 27: [/b] $resultmemb= mysql_query($sqlmemb) or die(mysql_error($mysql)); //get the number of rows in the result set; should be 1 if theres a match $isset1=mysql_num_rows($resultmemb); Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524941 Share on other sites More sharing options...
conker87 Posted April 23, 2008 Share Posted April 23, 2008 Is the $mysql variable the mysql_connect() variable? Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524952 Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 That means your query is bad, and you're passing a bad link to mysql_error(). Just do: /*Line 27*/ $resultmemb= mysql_query($sqlmemb) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524954 Share on other sites More sharing options...
sineadyd Posted April 23, 2008 Author Share Posted April 23, 2008 Ok cool. Now Im getting, No database selected. Thanks alot for all ur help so far, Im very grateful. Link to comment https://forums.phpfreaks.com/topic/102515-solved-login-script-trouble/#findComment-524970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.