Jump to content

script for login problem


sineadyd

Recommended Posts

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

//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

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)

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?

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.