473,738 Members | 3,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

login function got problem

127 New Member
Below is my login function, but it cant display the username correctly, i don't know what is the problem. Thanx..


LOGIN FUNCTION

<?php

extract ($_POST);

mysql_connect(" localhost","roo t","")
or die("Cannot connect to the server");

mysql_select_db ("dreamzdesign" )
or die("Cannot connect to the database");

$sql="select username from membership where username='$user name'";

$result=mysql_q uery($sql)
or die("Cannot execute query1");

$num=mysql_num_ rows($result);


if($num==1) //email valid
{
$sql="select username from membership where username='$user name' and password='$pass word'";

$result2=mysql_ query($sql)
or die("Cannot execute query");

$num2=mysql_num _rows($result2) ;
if($num2>0)
{
setcookie("User name", $username, time() + 60 * 60 * 24 * 5);

include("homepa ge.php");

}
else //message send to login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("login. php");
}
}
elseif($num==0) //message send to login.php when email not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("login. php");
}



?>

WELCOME MESSAGE

<?php
foreach ($_COOKIE as $key => $value)
?>
<h1 align="center"> <? echo $value; ?>, welcome to DreamZDesign !</h1>


HOMEPAGE

<?php
foreach ($_COOKIE as $key => $value)
?>

<h1 align="center"> <? echo $value; ?>, welcome to DreamZDesign !</h1>
Jan 18 '07 #1
6 1727
ronverdonk
4,258 Recognized Expert Specialist
Please read the Posting Guidelines before you post (code) in this forum!

moderator
Jan 18 '07 #2
bb nicole
127 New Member
Sorry. Below is my login function, welcome message and homepage. Thanx.

Login function
[PHP] <?php

extract ($_POST);

mysql_connect(" localhost","roo t","")
or die("Cannot connect to the server");

mysql_select_db ("dreamzdesign" )
or die("Cannot connect to the database");

$sql="select username from membership where username='$user name'";

$result=mysql_q uery($sql)
or die("Cannot execute query1");

$num=mysql_num_ rows($result);


if($num==1) //email valid
{
$sql="select username from membership where username='$user name' and password='$pass word'";

$result2=mysql_ query($sql)
or die("Cannot execute query");

$num2=mysql_num _rows($result2) ;
if($num2>0)
{
setcookie("User name", $username, time() + 60 * 60 * 24 * 5);

include("homepa ge.php");

}
else //message send to login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("login. php");
}
}
elseif($num==0) //message send to login.php when email not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("login. php");
}



?>[/PHP]

Welcome message

[HTML]<html>
<head>
<title>Welcom e <? echo $username; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

[PHP]<?php
foreach ($_COOKIE as $key => $value)
?>[/PHP]
<h1 align="center">[PHP]<? echo $value; ?>[PHP], welcome to DreamZDesign !</h1>
</body>
</html>
[/HTML]



Homepage

[PHP]<?php
foreach ($_COOKIE as $key => $value)
?>[/PHP]

[HTML]<html>
<head>
<title>DreamZDe sign</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #232122;
}
body,td,th {
color: #FFFFFF;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #CCCCCC;
}
a:active {
color: #CCCCCC;
}
-->
</style></head>

<body>
<p><img src="image/top%20banner.jp g" width="955" height="200"><a href="homepage. php"><img src="button/home.jpg" width="90" height="24" border="0"></a><a href="design.ph p"><img src="button/design%20zone.j pg" width="103" height="24" border="0"></a><a href="gallery.p hp"><img src="button/gallery.jpg" width="102" height="24" border="0"></a><a href="cart.php" ><img src="button/cart.jpg" width="68" height="24" border="0"></a><a href="forum.php "><img src="button/forum.jpg" width="51" height="24" border="0"></a><a href="faq.php"> <img src="button/faq.jpg" width="79" height="24" border="0"></a> <a href="aboutUs.p hp"><img src="button/about%20us.jpg" width="86" height="24" border="0"></a><a href="contactUS .php"><img src="button/contact%20us.jp g" width="121" height="24" border="0"></a>
</p><p align="center">

</p>
<h1 align="center">[PHP]<?php echo $value; ?>[/PHP], welcome to DreamZDesign !</h1>
<p><img src="image/main%20page.jpg " width="890" height="540"></p>
<p><img src="image/bottom%20banner .jpg" width="955" height="46"></p>
</body>
</html>[/HTML]
Jan 18 '07 #3
bb nicole
127 New Member
Sorry. Im new in php, below is my login page, login function, welcome message and homepage. Thanks.

LOGIN FUNCTION

[PHP]<?php

extract ($_POST);

mysql_connect(" localhost","roo t","")
or die("Cannot connect to the server");

mysql_select_db ("dreamzdesign" )
or die("Cannot connect to the database");

$sql="select username from membership where username='$user name'";

$result=mysql_q uery($sql)
or die("Cannot execute query1");

$num=mysql_num_ rows($result);


if($num==1) //email valid
{
$sql="select username from membership where username='$user name' and password='$pass word'";

$result2=mysql_ query($sql)
or die("Cannot execute query");

$num2=mysql_num _rows($result2) ;
if($num2>0)
{
setcookie("User name", $username, time() + 60 * 60 * 24 * 5);

include("homepa ge.php");

}
else //message send to login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("login. php");
}
}
elseif($num==0) //message send to login.php when email not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("login. php");
}



?>[/PHP]


LOGIN PAGE

[HTML]<html>
<head>
<title>DreamZDe sign</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #232122;
}
body,td,th {
color: #FFFFFF;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #CCCCCC;
}
a:active {
color: #CCCCCC;
}
-->
</style></head>

<body>
<p><img src="image/top%20banner.jp g" width="955" height="200">
</p>
<p align="center">[PHP]<?php echo $message;?>[/PHP]You MUST login before can use our services. If you don't have username please register <a href="register. php">here.</a> </p>
<form action='do_logi n.php' method='post'>
<p align="center"> Name : &nbsp;&nbsp;&nb sp;&nbsp;
<input type='text' name='username' size='24' maxlength='24'>
</p>
<p align="center"> Password :
<input type='password' name='password' size='24' maxlength='24'>
</p>
<p></p>
<p>
<center>
<input type='submit' name='submit' value='login' />
</center>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><img src="image/bottom%20banner .jpg" width="955" height="46"></p>
</body>
</html>[/HTML]


WELCOME MESSAGE

[HTML]<html>
<head>
<title>Welcom e <? echo $username; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
[PHP]<?php
foreach ($_COOKIE as $key => $value)
?>[/PHP]
<h1 align="center"> <? echo $value; ?>, welcome to DreamZDesign !</h1>
</body>
</html>[/HTML]

HOMEPAGE

[PHP]<?php
foreach ($_COOKIE as $key => $value)
?>
[/PHP]

[HTML]<html>
<head>
<title>DreamZDe sign</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #232122;
}
body,td,th {
color: #FFFFFF;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #CCCCCC;
}
a:active {
color: #CCCCCC;
}
-->
</style></head>

<body>
<p><img src="image/top%20banner.jp g" width="955" height="200"><a href="homepage. php"><img src="button/home.jpg" width="90" height="24" border="0"></a><a href="design.ph p"><img src="button/design%20zone.j pg" width="103" height="24" border="0"></a><a href="gallery.p hp"><img src="button/gallery.jpg" width="102" height="24" border="0"></a><a href="cart.php" ><img src="button/cart.jpg" width="68" height="24" border="0"></a><a href="forum.php "><img src="button/forum.jpg" width="51" height="24" border="0"></a><a href="faq.php"> <img src="button/faq.jpg" width="79" height="24" border="0"></a> <a href="aboutUs.p hp"><img src="button/about%20us.jpg" width="86" height="24" border="0"></a><a href="contactUS .php"><img src="button/contact%20us.jp g" width="121" height="24" border="0"></a>
</p><p align="center">

</p>
<h1 align="center">[PHP]<? echo $value; ?>[/PHP], welcome to DreamZDesign !</h1>
<p><img src="image/main%20page.jpg " width="890" height="540"></p>
<p><img src="image/bottom%20banner .jpg" width="955" height="46"></p>
</body>
</html>[/HTML]
Jan 18 '07 #4
bb nicole
127 New Member
What is the problem to my login function, it cant show the username correctly when user login, but it will show the name of the first user after the second user login..
what is the problem..
Jan 19 '07 #5
ronverdonk
4,258 Recognized Expert Specialist
Because you include() the homepage.php script, you can address the php variable $username from it. So instead, why don't you issue a [php]echo "Welcome $username";[/php] from that homepage.php script?

Ronald :cool:
Jan 19 '07 #6
bb nicole
127 New Member
thanks.. my login function already success!! Thanks..
Jan 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2969
by: Simon | last post by:
Hi, I have a Login.php page that logs the user in and out. I has two forms within the page, (depending on what we are trying to do), either one to log in or out. The form calls itself using a post method and either logs the user in our out given the information from the form. but every pages use sessions and cookies, if the user is successfully logged in then the cookies and session values are updated, (as well as MySQL).
1
5509
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to register a username and password & then login with those details, but so far I am having only marginal success. I am far from an expert on ASP programming, indeed the code I am using comes from "Sams Teach Yourself E-Commerce Programming with ASP" but it...
1
2669
by: Friends | last post by:
Hi I need to set security for row level but not based on Database user's login. It should be based on the user table login. For the particular user I need to allow only the particular records to access insert, update delete and select. Let me explain clearly For example think we are using asp/asp.net website
2
2058
by: Tom | last post by:
I hope someone can help me figure out what's going on here. I've re-read the section on sessions at php.net and Googled this high and low but I haven't found anything that quite explains my problem. The basic problem: session data (e.g. $_SESSION) gets dropped after visitor logs in and reloads the page via a form once or twice (it seems to vary), requiring the visitor to re-login, whereupon the problem repeats itself. An outline of...
1
3071
by: xcelmind | last post by:
Hello Dev. Guru, I want to at this time introduce myself. I am Stanley Ojadovwa by name. I’m a freelance and a newbie in web application development. I’m currently using ASP as my application server technology with Microsoft access as my database source. Just as I have introduced myself, I’m a newbie in web application development. I’m currently working on an application that will allow
13
3250
JodiPhillips
by: JodiPhillips | last post by:
G'day, I have a silly and simple problem that I need some guidance with. Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log in procedures via a log in table within the database. This works fine. I have now expanded this table to include further data about the authorised user – Power User, Team Leader, & Facilitator. Depending on the user’s status as to which one of...
3
6223
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it has to tell then them its wrong information but currently it takes then to a next page and then tells them its incorrect information. This is tedious as every time they enter wrong they will be redirected to a different page and then they have to...
10
4819
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey Jones, then login as David Smith the Welcome message below will show "Welcome Davey". And it will be Davey's information that is accessible - not David Smith's. So something is amiss but I don't know what. (BTW, this login script is based on the...
13
4173
by: Apostle | last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting the progress and I hope you guys will help me. The code below is what I have so far. Just put two scripts in the same directory and that is! I hope you will help me Thanks! class.php <?php //php login sytem class LoginRegister{ function...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.