By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Problem communication with database

P: 28
i using ubuntu lamp server.
In my mysql database i have a table called users, which store the user and there password. i created a php page called login.php where you bacially have to log into.
when i am running the page and type in a user and there password and click submit button. All that happening is text fields become clear and that it.
how do i solve this problem?
Feb 14 '08 #1
Share this Question
Share on Google+
9 Replies


harshmaul
Expert 100+
P: 490
Hi,
just stick the user ID in to a session variable/cookie, and then us that to tell whether the user is logged in.

Secondly when the user submits the form and you have confirmed and logged the session.... use

Expand|Select|Wrap|Line Numbers
  1. header("location:nextpage.php");
to display the index of the next page after logging in.

http://www.codersadvocate.com/blogs/...dministration/

Heres an article i wrote a while back that might help you
Feb 14 '08 #2

nathj
Expert 100+
P: 938
i using ubuntu lamp server.
In my mysql database i have a table called users, which store the user and there password. i created a php page called login.php where you bacially have to log into.
when i am running the page and type in a user and there password and click submit button. All that happening is text fields become clear and that it.
how do i solve this problem?

Hi,
Let's see some code. I'd like to see the login.php and any code used to query the database that is not in this file. It would also be useful to know the data structure.

Post it all back here and I'll try to help out.

Cheers
nathj
Feb 14 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
Welcome to TSDN pricelindie!

For the structure of such a login script, have a peek HERE and check if your application lacks something.

Ronald
Feb 14 '08 #4

P: 28
Hi,
Let's see some code. I'd like to see the login.php and any code used to query the database that is not in this file. It would also be useful to know the data structure.

Post it all back here and I'll try to help out.

Cheers
nathj
[php]
[<?session_start()?>
<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>login</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<?php
$links = "<a href='main.php'> GO to main page</a><br><a href= 'logout.php'> Go to logout";


if ($user && $pass){
if ($logged_in_user ==$user){
echo $user.", You are already logged in.<br><br>";
echo $links;
exit;
}
$db =mysql_connect("localhost","whitney","password")or die
("Error connecting to database");
mysql_select_db ("computer_room,$db");
$result = mysql_query("SELECT * FROM users WHERE name ='".$user."'AND password=PASSWORD('".$pass."')");

if (!$result){
echo "Sorry, there has been a technical error. You cannot enter";
exit;
}
if(mysql_num_rows($result)>0){
$logged_in_user =$user;
session_register(logged_in_user);
echo "Welcome to Computer Room Equipment Database";
exit;
}
else {
echo "Your Login attempt failed";
}
}
else if ($user || $pass){
echo "Please fill in bothe fields<br>";
}
?>

thanks

<form action="login.php" method="post" enctype="text/plain">
Your Username:
<input type="text" name="user" value="" size="40" maxlength="40"/>
<br>
Your Password:

<input type="text" name="pass" value="" size="40" maxlength="40"/>
<br>

<input type="submit" name="" value="Login"/>



</form>

</body>
</html>

[/php]
Feb 14 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
Where did you put the statements that pick up the userid and password from the $_POST array. Because you did a POST on that form.
So you'll have to start your script with something (but not exactly) like
[php]
if (isset($_POST['user'] AND isset($_POST['pass'])) {
$user=strip_tags($_POST['user']);
$pass=strip_tags($_POST['pass');
//
// cleanse and check validity of the POSTed fields to avoid any attacks
//
}
[/php]
Btw: what is this statement doing?? Does not look quite correct. What databasename is 'computer_room,$db' ?
[php]
mysql_select_db ("computer_room,$db");
[/php]

Ronald
Feb 14 '08 #6

P: 28
Thanks.. it Work fine..
Feb 18 '08 #7

ronverdonk
Expert 2.5K+
P: 4,258
Thanks.. it Work fine..
Good that it works. Could you please share with us how you solved your problem? Thanks and see you again.

Ronald
Feb 18 '08 #8

P: 28
It work by putting a statement to pick up the user and pass from the $_POST.

Thanks Ronald.

Code: ( php )
if (isset($_POST['user'] AND isset($_POST['pass'])) {
$user=strip_tags($_POST['user']);
$pass=strip_tags($_POST['pass');
//
// cleanse and check validity of the POSTed fields to avoid any attacks
//
}
Feb 19 '08 #9

ronverdonk
Expert 2.5K+
P: 4,258
Ok you got it. See you next time here.

Ronald
Feb 19 '08 #10

Post your reply

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