/    Sign up×
Community /Pin to ProfileBookmark

login script trouble

Hi,
was just wondering if anyone could help me with this code, Im doing a login page and my php script for a successful login doesnt work for me.Can any1 spot something I’ve missed? my database is “users” and the tables I need in it are admin and members.

[code=php]successlogin.php
<?php
//Connect to server and select database.
$mysqli = mysqli_connect(“$host”, “$username”,”$password”,”$db_name”) or die(“connection was unsuccessful”);
mysql_select_db(“$db_name”)or die(“Database connection was unsuccessful”);

//Users Database settings
$host=”localhost”;
$username=”root”;
$password=””;
$db_name=”users”;

//User database tables needed.
$tbl_memb=”members”;
$tbl_admin=”admin”;

//create and issue the query
$username=$_POST[‘USERNAME’];
$password=$_POST[‘PASSWORD’];

$sql=”SELECT * FROM tbl_memb WHERE
username = ‘”.$_POST[“USERNAME”].”‘ AND password = PASSWORD(‘”.$_POST[“PASSWORD”].”‘)”;
$resultmemb= mysqli_query($sqlmemb) or die(mysqli_error($mysqli));

//get the number of rows in the result set; should be 1 if theres a match
isset1=mysqli_num_rows($resultmembs);

$sql=”SELECT * FROM tbl_memb WHERE
username = ‘”.$_POST[“USERNAME”].”‘ AND password = PASSWORD(‘”.$_POST[“PASSWORD”].”‘)”;
$resultadmin= mysqli_query($sqladmin) or die(mysqli_error($mysqli));
//get the number of rows in the result set; should be 1 if theres a match
isset2=mysqli_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(‘../Login/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=”error”>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>[/code]

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@Shanu_chaudharyApr 22.2008 — Wont U get errors while running this script with these erors....

U forgot to place "$" b4 isset1 and isset2 in some places ? ? and some syntax errors... As mysql is not working in my machine I just modified the syntax errors...
[code=php]<?php
//Connect to server and select database.
$mysqli = mysqli_connect("$host", "$username","$password","$db_name") or die("connection was unsuccessful");
mysql_select_db("$db_name")or die("Database connection was unsuccessful");

//Users Database settings
$host="localhost";
$username="root";
$password="";
$db_name="users";

//User database tables needed.
$tbl_memb="members";
$tbl_admin="admin";

//create and issue the query
$username=$_POST['USERNAME'];
$password=$_POST['PASSWORD'];

$sql="SELECT * FROM tbl_memb WHERE
username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')";
$resultmemb= mysqli_query($sqlmemb) or die(mysqli_error($mysqli));

//get the number of rows in the result set; should be 1 if theres a match
$isset1=mysqli_num_rows($resultmembs);

$sql="SELECT * FROM tbl_memb WHERE
username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')";
$resultadmin= mysqli_query($sqladmin) or die(mysqli_error($mysqli));
//get the number of rows in the result set; should be 1 if theres a match
$isset2=mysqli_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('../Login/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="error">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>[/code]


Hope this Helps u to some extent...?
Copy linkTweet thisAlerts:
@sineadydauthorApr 22.2008 — thanks very much, i really appreciate ur help!
Copy linkTweet thisAlerts:
@Shanu_chaudharyApr 22.2008 — thanks very much, i really appreciate ur help![/QUOTE]

Welcome...?

Whether ur' Problem Solved or not????
Copy linkTweet thisAlerts:
@sineadydauthorApr 22.2008 — unfortunately no, I have 2 errors now.
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:wampwwwLOGINlogin.php on line 10

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:wampwwwLOGINlogin.php on line 10

Database connection was unsuccessful[/QUOTE]


I had this before but to be honest, I forget how I fixed it then, so Im just messing around with it to see if I can fix it.any suggestions are welcome.
Copy linkTweet thisAlerts:
@Shanu_chaudharyApr 22.2008 — $mysqli = mysqli_connect($host, $username,$password,$db_name) or die("connection was unsuccessful");

mysql_select_db($db_name)or die("Database connection was unsuccessful");

U can't keep the variables in quotes...Ofcourse may be this is not a problem i think...

Declare the variables first and then call the connect function..

Hope it works...
Copy linkTweet thisAlerts:
@sineadydauthorApr 22.2008 — yeah I've done that but still no luck, so I changed:
[code=php]mysql_select_db($db_name)or die("Database connection was unsuccessful");
-> $mysqli= mysqli_select_db("$db_name")or die("Database connection was unsuccessful");
[/code]

And i got this error:
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:wampwwwLOGINlogin.php on line 10

Database connection was unsuccessful[/QUOTE]


Here is my code again:
[code=php]<?php
//Users Database settings
$host="localhost";
$username="root";
$password="";
$db_name="users";

//Connect to server and select database.
$mysqli= mysqli_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'];

$sql="SELECT * FROM tbl_memb WHERE
username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')";
$resultmemb= mysqli_query($sqlmemb) or die(mysqli_error($mysqli));
//get the number of rows in the result set; should be 1 if theres a match
$isset1=mysql_num_rows($resultmembs);

$sql="SELECT * FROM tbl_memb WHERE
username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')";
$resultadmin= mysqli_query($sqladmin) or die(mysqli_error($mysqli));
//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="error">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>
[/code]
Copy linkTweet thisAlerts:
@roscorApr 22.2008 — I see an error here
[code=php]$sql="SELECT * FROM tbl_memb WHERE
username = '".$_POST["USERNAME"]."' AND password = PASSWORD('".$_POST["PASSWORD"]."')";
$resultmemb= mysqli_query($sqlmemb) or die(mysqli_error($mysqli));
//get the number of rows in the result set; should be 1 if theres a match
$isset1=mysql_num_rows($resultmembs);
[/code]
where you [COLOR=#000000][COLOR=#0000bb]$sql[/COLOR][COLOR=#007700] = [/COLOR][COLOR=#dd0000]"SELECT * FROM[/COLOR][/COLOR][COLOR=#000000][COLOR=#dd0000] tbl_memb (missing a '$' = $tbl_memb)[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]



[COLOR=Black] why not just use[/COLOR] [/COLOR]
[/COLOR]
[COLOR=#000000][COLOR=#0000bb]$sql [/COLOR][COLOR=#007700]=[/COLOR][COLOR=#dd0000] "SELECT * FROM members WHERE.....[/COLOR][/COLOR]
Copy linkTweet thisAlerts:
@sineadydauthorApr 22.2008 — I could use either they are declared prior to those lines of code.Probly would be easier to just use members though, that way I wont keep forgetting the "$".It still isn't working tho, I might leave it alone 4 today now, its quite annoying me!
Copy linkTweet thisAlerts:
@jasonahouleApr 22.2008 — Use mysql_query() and not mysqli_query(). If you want to use the mysqli functions then you should use them when creating your connection also.
×

Success!

Help @sineadyd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...